I'm developing an Yii2 extension that uses an AssetBundle for some js/css files:
namespace myExtension/assets;
class ResourcesAsset extends AssetBundle {
public $sourcePath = '@app/assets/resources';
public $css = ['resources.css'];
public $js = ['resources.js'];
public $depends = ['yii\bootstrap\BootstrapPluginAsset'];
}
Structure in extension:
my-extension
|-assets
| |-resources
| |-resources.css
| |-resources.js
| ResourceAsset.php
|-controllers
|-models
|-views
|-Module.php
This doesn't seem to work when I install the extension in another project because of the $sourcePath
. There the alias @app
points to the application base path, not to the extension root folder in vendor.
Currently, I use @myExtension/assets/resources
, which works as I know it gets that alias in extionsions.php when it gets installed. But I think this is not optimal. So what is the optimal way to declare $sourcePath
? Should I create an own alias (in Module.php?)? Should I use __DIR__
?