我已在yii2-advanced中安装了yii2-bootstrap4扩展名,并添加了一个自定义的css文件(custom.css
),该文件使用Sass重新编译Bootstrap源。
然后我将custom.css
添加到frontend/web/css
,并按如下所示修改了frontend/assets/AppAsset.php
:
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/custom.css',
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap4\BootstrapAsset',
];
}
我获得了想要的结果,但是我发现页面的<head>...</head>
包含以下内容:
<link href="/yii2-advanced/frontend/web/assets/1758a11a/css/bootstrap.css" rel="stylesheet">
<link href="/yii2-advanced/frontend/web/css/custom.css" rel="stylesheet">
<link href="/yii2-advanced/frontend/web/css/site.css" rel="stylesheet"></head>
和:
[...]/css/bootstrap.css
包含原始Bootstrap 4 CSS问题
[...]/css/bootstrap.css
?适应了此other question的答案之一(由@ Sfili_81建议),我解决了如下修改frontend/assets/AppAsset.php
的问题:
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/custom.css',
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap4\BootstrapAsset',
];
public function init(){
parent::init();
// resetting BootstrapAsset to not load own css files
\Yii::$app->assetManager->bundles['yii\\bootstrap4\\BootstrapAsset'] = [
'css' => [],
//'js' => []
];
}
}
现在<head>
部分中包含的css文件只是这些文件:
<link href="/yii2-advanced/frontend/web/css/custom.css" rel="stylesheet">
<link href="/yii2-advanced/frontend/web/css/site.css" rel="stylesheet">