首页 > 解决方案 > Yii2:重载扩展的CSS

问题描述

我正在使用扩展dmstr/yii2-cookie-consent来获得 cookie 同意,并且我想修改扩展的 CSS。扩展中的 CSS 作为 AssetBundle 包含在内。

以下是我的问题:

标签: cssyii2assets

解决方案


在开发过程中,您可以使用

$this->registerCss(".your-css {}")

用于原型制作

上线时,您可以使用依赖注入重载扩展资产包

'assetManager' => [
    'bundles' => [
        'dmstr\cookieconsent\assets\CookieConsentAsset' => [
            'sourcePath' => '/path/to/your/source/path',
            'css' => [
                'css/yourstyles.css'
            ]
        ]
    ]
]

请记住,该包提供了根据应用程序环境加载资产的功能。在生产模式下,会加载 css 的压缩版本。

https://github.com/dmstr/yii2-cookie-consent/blob/master/src/assets/CookieConsentAsset.php#L20


推荐阅读