Answer the question
In order to leave comments, you need to log in
yii asset/template command in YII?
Trying to tame JquerySparkline . The problem is that there is no ready-built sparkline-js file on the github in the native repository (strange, but the author believes that this is better and publishes only individual modules that everyone should build for themselves, well, or all together).
Writing a resource file for Sparkline
common/assets/sparkline/Gwatts_JquerySparklineAsset_combine.php
:class Gwatts_JquerySparklineAsset_combine extends AssetBundle
{
public $sourcePath = '@vendor/gwatts/jquery.sparkline/src';
public $js = [
'header.js',
'defaults.js',
'utils.js',
'simpledraw.js',
'rangemap.js',
'interact.js',
'base.js',
'chart-line.js',
'chart-bar.js',
'chart-tristate.js',
'chart-discrete.js',
'chart-bullet.js',
'chart-pie.js',
'chart-box.js',
'vcanvas-base.js',
'vcanvas-canvas.js',
'vcanvas-vml.js',
'footer.js',
];
}
yii asset/template common/assets/sparkline/Gwatts_JquerySparklineAsset_config.php
, a file is created, I go into it and configure:// я не хочу сразу публиковать собранный файл на прод, а хочу оставить его внутри проекта, чтобы потом подключать к двум поддоменам поотдельности
// файл будет лежать в папке common/assets/sparkline/sparkline.js
Yii::setAlias('@webroot', __DIR__.'/sparkline');
Yii::setAlias('@web', '/');
return [
// Adjust command/callback for JavaScript files compressing:
'jsCompressor' => 'java -jar compiler.jar --js {from} --js_output_file {to}',
// Adjust command/callback for CSS files compressing:
'cssCompressor' => 'java -jar yuicompressor.jar --type css {from} -o {to}',
// The list of asset bundles to compress:
'bundles' => [
// этот файл содержит список тех самых js-кусков кода, которые необходимо собрать
// описание его ниже
common\assets\Gwatts_JquerySparklineAsset_combine::className(),
],
// Asset bundle for compression output:
'targets' => [
'Gwatts_JquerySparklineAsset' => [
'class' => common\assets\Gwatts_JquerySparklineAsset_combine::className(),
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'sparkline.js',
],
],
// Asset manager configuration:
'assetManager' => [
'basePath' => '@webroot',
'baseUrl' => '@web',
],
];
yii asset/compress common/assets/sparkline/Gwatts_JquerySparklineAsset_config.php common/assets/sparkline/Gwatts_JquerySparklineAsset_bundle.php
. As a result, a common/assets/sparkline
folder 3c99cc05
with all our js pieces and a sparkline.js
. It also creates a file Gwatts_JquerySparklineAsset_bundle.php
with the following content:return [
'Gwatts_JquerySparklineAsset' => [
'class' => 'common\\assets\\Gwatts_JquerySparklineAsset_combine',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => [
'sparkline.js',
],
'css' => [],
],
'common\\assets\\Gwatts_JquerySparklineAsset_combine' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'Gwatts_JquerySparklineAsset',
],
],
];
Gwatts_JquerySparklineAsset
:class Gwatts_JquerySparklineAsset extends AssetBundle
{
public $sourcePath = '@common/assets/sparkline';
public $js = [
'sparkline.js',
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question