Answer the question
In order to leave comments, you need to log in
YII2 Assets minification and correct connection of CSS and JS to the project?
Hello!
Actually, this is the question: There is an AppAssets class on the YII 2 project, this class contains css and js files that should be included in the project.
class AppAsset extends AssetBundle
{
public $sourcePath = '@app/assets/themes/';
public $css = [
'css/normalize.css',
'css/template_2.css',
'css/template.css',
'css/roboto.css',
'css/jquery.selectbox.css',
'css/jquery.ui.css',
'css/icheck.css'
];
public $js = [
'js/vendors/jquery-1.7.2.min.js',
'js/ui/jquery.ui.core.js',
'js/ui/jquery.ui.widget.js',
'js/ui/jquery.ui.autocomplete.js',
'js/ui/jquery.ui.dialog.js',
'js/vendors/jquery.maskedinput.js',
'js/vendors/jquery.selectbox-0.2.min.js',
'js/vendors/jquery.html5-placeholder-shim.js',
'js/vendors/jquery.icheck.min.js',
'js/vendors/underscore-min.js',
'themes/smart_admin/theme/js/plugin/jquery-validate/jquery.validate.min.js',
'js/public/common.js',
'js/page/evac_request.js',
'js/page/buy_cards.js'
];
public $jsOptions = [
'position' => \yii\web\View::POS_HEAD
];
public $cssOptions = [
'position' => \yii\web\View::POS_HEAD
];
public $depends = [
'yii\web\YiiAsset',
];
public $publishOptions = [
'forceCopy' => true
];
}
Yii::setAlias('@webroot', __DIR__ . '/../web');
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' => [
'app\assets\AppAsset',
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
],
// Asset bundle for compression output:
'targets' => [
'app\assets\AppAsset' => [
'basePath' => '@webroot/',
'baseUrl' => '@web/',
'css' => 'css/all-front-{hash}.css',
'js' => 'js/all-front-{hash}.js',
'depends' => [
// Include all assets shared between 'backend' and 'frontend'
'app\assets\AppAsset',
'yii\web\YiiAsset',
'yii\web\JqueryAsset'
],
],
],
// Asset manager configuration:
'assetManager' => [
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets',
],
];
sudo ./yii asset config/assets.php assets/assets_min.php
return [
'app\\assets\\AppAsset' => [
'class' => 'app\\assets\\AppAsset',
'basePath' => '@webroot/',
'baseUrl' => '@web/',
'js' => [
'js/vendors/jquery-1.7.2.min.js',
'js/ui/jquery.ui.core.js',
'js/ui/jquery.ui.widget.js',
'js/ui/jquery.ui.autocomplete.js',
'js/ui/jquery.ui.dialog.js',
'js/vendors/jquery.maskedinput.js',
'js/vendors/jquery.selectbox-0.2.min.js',
'js/vendors/jquery.html5-placeholder-shim.js',
'js/vendors/jquery.icheck.min.js',
'js/vendors/underscore-min.js',
'themes/smart_admin/theme/js/plugin/jquery-validate/jquery.validate.min.js',
'js/public/common.js',
'js/page/evac_request.js',
'js/page/buy_cards.js',
],
'css' => [
'css/normalize.css',
'css/template_2.css',
'css/template.css',
'css/roboto.css',
'css/jquery.selectbox.css',
'css/jquery.ui.css',
'css/icheck.css',
],
],
'yii\\web\\JqueryAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'app\\assets\\AppAsset',
],
],
'yii\\web\\YiiAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'yii\\web\\JqueryAsset',
'app\\assets\\AppAsset',
],
],
];
Answer the question
In order to leave comments, you need to log in
And if so?
...
// Asset bundle for compression output:
'targets' => [
'frontend' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot/',
'baseUrl' => '@web/',
'css' => 'css/all-front-{hash}.css',
'js' => 'js/all-front-{hash}.js',
'depends' => [
// Include all assets shared between 'backend' and 'frontend'
'app\assets\AppAsset',
'yii\web\YiiAsset',
'yii\web\JqueryAsset'
],
],
],
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question