New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootstrap css asset is always loaded? #1263
Comments
Perhaps you used some bootstrap widget, such as |
@qiangxue Yes, I do, but my own css contains code to style it. I'm worried about mobile performance, so I want to keep the number of HTTP requests and download size to a minimum. It seems logical to me that the Bootstrap css should only be loaded if I include it in the AppAssets. |
I have done the same, using bootstrap less sources. I just configured Assetmanager::bundles so that bootstrap asset does not load any case file. |
@cebe Can you show me an example of your code? |
@qiangxue @cebe I assume you are talking about Yii::$app->assetManager->bundles or am I mistaken? I'm probably forgetting something, but please paste an example of your solution. It will help not only me, but also anyone else searching for clues :-) |
try this: 'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
]
] |
@qiangxue thank you, you guys are wonderful. |
@qiangxue But when I call gii module bootstrap css is missing because of the above config |
You may override bootstrap asset in your AppAsset::init() to have the changes only applied when your asset is loaded. |
like this: class AppAsset extends AssetBundle
{
// ...
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
public function init()
{
parent::init();
// resetting BootstrapAsset to not load own css files
Yii::$app->assetManager->bundles['yii\\bootstrap\\BootstrapAsset'] = [
'css' => []
];
}
} |
@cebe |
Yeah, right... need to check whether we can improve this somehow... |
Thank you @cebe |
It seems gii and debug modules should reset |
agree. |
I did another try. 'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'basePath' => '@webroot',
'baseUrl' => '@web',
'css' => ['css/bootstrap.css']
],
],
], now it always loads my css bootstrap, gii too. |
I don't think this is fixed. I have the same problem as #974. I want to use my custom Bootstrap built from the LESS sources, so I did as suggested above: 'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
]
] Now the debug toolbar is broken as the In my main layout I register the namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
public $depends = [
'app\assets\BootstrapAsset',
'yii\bootstrap\BootstrapPluginAsset',
];
} And my custom namespace app\assets;
use yii\web\AssetBundle;
class BootstrapAsset extends AssetBundle
{
public $sourcePath = '@app/less';
public $css = [
'application/main.less',
];
} As a workaround I've changed the namespace of my Yii::$classMap['yii\bootstrap\BootstrapAsset'] = realpath(__DIR__.'/../assets/BootstrapAsset.php'); |
the issues is still open ;) |
Oh, right, sorry. I was mislead by the link to #974. |
I have my own CSS file, which I compile using less and which contains all the bootstrap code. Thus, I do not want to include the default bootstrap.css
I succeeded in registering my own CSS file in the \backend\assets\AppAsset.php file.
However, I also commented out the line that includes yii\bootstrap\BootstrapAsset as an item in the $depends array, and it keeps being included.
The only way I'm able to disable it, is by modifying the $css array in the yii-bootstrap vendor directory, but this is obviously not a good solution.
Any thoughts on this?
The text was updated successfully, but these errors were encountered: