Yii2 How to prevent autoloading of assetsbundle of any widget?

自作多情 提交于 2019-12-11 11:40:42

问题


I am using \yii\jui\AutoComplete

It automatically loads the JuiAssets. Is there any way to prevent loading files of JuiAssets? I want to use my own version of files. In the previous version of Yii Framework, we had option to prevent loading the associated css and js files of any widget.

Is there any way to change the AssetBundle for any jui Widget, without editing its core files?


回答1:


Yes, you can easily customize any AssetBundle to fit your needs:

1) Through application config:

return [
    'components' => [
        'assetManager' => [
            'bundles' => [
                'yii\jui\JuiAsset' => [
                    'sourcePath' => null, // do not publish the bundle
                    'js' => [
                        // replace published js file here
                    ],
                ],
            ],
        ],
    ],
];

2) You can do the same at runtime through assetManager component:

Yii::$app->assetManager->bundles['yii\jui\JuiAsset'] = [
    'sourcePath' => null,
    'js' => [...],
];

Official documentation:

  • Customizing Asset Bundles
  • assetManager component

Note that logic for registering jQuery UI components was changed in this commit. So there is no separate asset bundle for Autocomplete, etc. They all use yii\jui\JuiAsset.



来源:https://stackoverflow.com/questions/29052194/yii2-how-to-prevent-autoloading-of-assetsbundle-of-any-widget

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