About the correct posture of $ publishOptions in Yii2 AssetBundle, yii2assetbundle
This article describes how to use the correct posture of $ publishOptions in Yii2 AssetBundle. The details are as follows:
Official documents: http://www.yiiframework.com/doc-2.0/guide-structure-assets.html
If you are interested, you can read the original document of the official website.
Sample Code
<?phpnamespace app\assets; use yii\web\AssetBundle; class FontAwesomeAsset extends AssetBundle { public $sourcePath = '@bower/font-awesome'; public $css = [ 'css/font-awesome.min.css', ]; public $publishOptions = [ 'only' => [ 'fonts/', 'css/', ] ];}
The official documentation shows that only the fonts and css resource directories are published after such configuration.
The above example defines an asset bundle for the "fontawesome" package.
By specifying the only publishing option,
Only the fonts and css subdirectories will be published.
Why is it wrong, because it is unable to meet the requirements for publishing the fonts and css directories described in the official website documentation.
The correct syntax is as follows:
//... public $publishOptions = [ 'only' => [ 'fonts/*', 'css/*', ] ];
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.