yiisoft / yii2-bootstrap5

Yii 2 Bootstrap 5 Extension
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
59 stars 37 forks source link

Update BootstrapAsset #52

Closed WinterSilence closed 1 year ago

WinterSilence commented 1 year ago
Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues
simialbi commented 1 year ago

This could be relevant for some developers (e.g. with asset compressing. Closure compile does not like already compressed files). Could you please add a CHANGELOG entry?

WinterSilence commented 1 year ago

@simialbi in first case, #51 and #52 fix problems with invalid paths in source maps: need keep folder's structure at publishing assets

julianrutten commented 1 year ago

This change is breaking.

If you use the console asset controller to compress your assets. (https://www.yiiframework.com/doc/api/2.0/yii-console-controllers-assetcontroller) and your configuration bundles includes:

         'yii\bootstrap5\BootstrapAsset',
         'yii\bootstrap5\BootstrapPluginAsset',
         'yii\bootstrap5\BootstrapIconAsset',

Then you get the following error:

PHP Warning 'yii\base\ErrorException' with message 'file_get_contents(app/frontend/web/assets/c13acc9d/dist/js/bootstrap.bundle.js): failed to open stream: No such file or directory'

Because the default hasher of AssetManager is only based on the dir both Assets have the same $dstDir (assets destination directory), since BootstrapAsset was run first it excludes all JS (or vice versa if you include BootstrapPluginAsset and it depends on BootstrapAsset). Then when BootstrapPluginAsset is registered it assumes the directory contains its assets (since it exists) but it does not since only CSS was copied. See: https://github.com/yiisoft/yii2/blob/277be0b8e789573e0e4ba912db298929e46a8737/framework/web/AssetManager.php#L553