phptwitter-bootstrapyii2yii-extensions

Yii2 disable Bootstrap Js, JQuery and CSS


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?


Solution

  • 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
    ];