Yii2 disable Bootstrap Js, JQuery and CSS

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 18:55:21

问题


Same as title, i don't want using bootstrap.css and bootstrap.js. I try using:

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

It remove bootstrap.css but can't remove bootstrap.js. Somebody can help me?


回答1:


In web.php config file add the following code into components array:

'assetManager' => [
        'bundles' => [
            'yii\bootstrap\BootstrapPluginAsset' => [
                'js'=>[]
            ],
        ],
    ],

To be more comprehensive:

in order to disable Css (bootstrap.css):

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

in order to disable JS (bootstrap.js):

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
    ],
],

in order to disable JQuery (jquery.js)

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
    ],
],

In order to have all of them disabled:

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],

    ],
],

UPDATE

As Soju mentioned in comments, another alternative way would be disabling these files in AppAsset class, which is located in ./assets/, then remove the following lines:

public $depends = [
   'yii\web\YiiAsset',              #REMOVE
   'yii\bootstrap\BootstrapAsset',  #REMOVE
];



回答2:


For anyone that gets "Invalid Call" errors you have to add Ali's answer to 'components' in $config variable in app/config/web.php E.g.

'components' => [
    'assetManager' => [
        'bundles' => [
            'yii\web\JqueryAsset' => [
                'js'=>[]
            ],
            'yii\bootstrap\BootstrapPluginAsset' => [
                'js'=>[]
            ],
            'yii\bootstrap\BootstrapAsset' => [
                'css' => []
            ]
        ]
    ],
    ...
],



回答3:


On AppAsset.php file add this:

public function init()
{
    parent::init();
    // resetting BootstrapAsset to not load own css files
    \Yii::$app->assetManager->bundles['yii\\bootstrap\\BootstrapAsset'] = [
        'css' => [],
        'js' => []
    ];
}


来源:https://stackoverflow.com/questions/26734385/yii2-disable-bootstrap-js-jquery-and-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!