برای این کار روش های متنوعی وجود داره که یکی از مفید ترینشون که من استفاده کردم
استفاده از ویجتی Yii 2 Minify View Component می باشد
برای استفاده از این ماژول ابتدا به وسیله ی composer آن را در اپلیکیشن خود نصب کنید:
[php] composer require "rmrevin/yii2-minify-view:~1.13" [/php]
یا قرار دادن کد زیر در فایل composer.json در رووت سایت (در قسمت require)
[php] "rmrevin/yii2-minify-view": "~1.13", [/php]
برای اعمال تنظیمات
کد زیر را در components در main.php یا web.php در فولدر config قرار دهید :
[php]
'view' => [
'class' => 'rmrevinyiiminifyView',
'enableMinify' => !YII_DEBUG,
'concatCss' => true, // concatenate css
'minifyCss' => true, // minificate css
'concatJs' => true, // concatenate js
'minifyJs' => true, // minificate js
'minifyOutput' => true, // minificate result html page
'web_path' => '@web', // path alias to web base
'base_path' => '@webroot', // path alias to web base
'minify_path' => '@webroot/minify', // path alias to save minify result
'js_position' => [ yiiwebView::POS_END ], // positions of js files to be minified
'force_charset' => 'UTF-8', // charset forcibly assign, otherwise will use all of the files found charset
'expand_imports' => true, // whether to change @import on content
'compress_options' => ['extra' => true], // options for compress
'excludeBundles' => [
devhellowrldAssetBundle::class, // exclude this bundle from minification
],
]
[/php]
با اجرای اپلیکیشن در فولدر web فولدری با نام minify ایجاد می شود که برای css ها فایلی جداگانه و برای js ها نیز فایلی جداگانه ایجاد می کند .
برچسب:
نویسنده: پندار توکلی