Your support helps keep this blog running! Secure payments via Paypal and Stripe.
With Yii2, it comes with the asset management calls asset bundle. An asset bundle is simply a collection of assets located in a directory. When you register an asset bundle in a view, it will include the CSS and JavaScript files in the bundle in the rendered Web page.
Below is my asset bundle setting in my application. I use the advanced template from Yii2, and I use the frontend for my application(backend, console, and frontend folders are generated from the advanced template from Yii2). The code snippet below is in the AppAsset.php you can name the file whatever you need. The location is the same as the namespace of the Yii2 standard.
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
?>I set up Gulp for compiling the Sass file and put the generated CSS, JS, or fonts file in frontend/web/assets. The frontend/web is my root application. That means Yii will cache all CSS, fonts, and JS files in frontend/web/assets. Every time I run gulp to change the style or JS script, or fonts file, I have to delete all cache files in frontend/web/assets, then refresh my browser(Ctrl+F5 for Windows) to see the changes. And that’s it.
Your support helps keep this blog running! Secure payments via Paypal and Stripe.
