This article mainly introduces the example of using less to replace css in yii2. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
Add componentsphp composer.phar require --prefer-dist singrana/yii2-less "*"
Modify Configuration file `main.php'
'components' => [ 'assetManager' => [ 'converter' => [ 'class' => \singrana\assets\Converter::className(), ], ], ],
In AppAsset
class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/site.less', //*.less代替*.css并在css目录中使用.less后缀的,并在版本库中忽略.css文件 ]; public $js = [ ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; }
This way you can use less to write styles
The above is the detailed content of Detailed code example of using less instead of css in yii2. For more information, please follow other related articles on the PHP Chinese website!