Yii Framework Forum

Path-Aliasses in own asset bundles


(Baender3002) #1

Hey,

I’m using my own asset bundles, which it is documented here: https://www.yiiframework.com/doc/guide/2.0/en/structure-assets

I have the following best practice questions:

1.) the documentation says, “It is recommended that you place assets belonging to an application in a Web directory to avoid the unnecessary asset publishing process.”. But if you use composer with npm and bower assets, all the extensions are placed into the vendor directory. So I think, using the sourcePathe parameter, to trigger the asset bundle publishing process is an better workflow, instead of copying each time the files from vendor directory to the webroot. Right? No?

2.) The sourcePath parameter supports path assesses, like @bower OR @npm. In my case, I like to bundle JS corde from bower path AND npm path. In this case, I must use the parent directory @vendor at the sourcePath parameter. In this case I’m loosing the benefits, which I had, if I would use aliases for bower and npm paths.
As far as I know, the following will not work:

class MyAsset extends AssetBundle
{
    public $sourcePath = '@vendor';
     public $css = [  ];
    public $js = [
        '@bower/first.js',
        '@npm/2nd.js'
    ];
    public $depends = [  ];
}

What is your recommendation, how to set source Path if the sources are located in different directories?

Thank you.