Assetbundle to include files

Hello,

Are there any way of including files from different folders in an assetbundle?

For example, lets say i am creating an assetbundle and this bungle include css and js from a folder "vendor/bower/myplugin/myjsfile.js" and "vendor/bower/myplugin/mycssfile.css". But then i have some default config in another jsfile under "web/js" which should also be part of the asset. How do we tackle this?




<?php


namespace frontend\assets;


use yii\web\AssetBundle;


class MyTestAsset extends AssetBundle

{

    public $sourcePath = '@bower/myplugin';


    public $css = [

        'myplugin.min.css'

    ];

    public $js = [

        'myplugin.min.js',

        // myconfig.js - this file is found under web/js

    ];

    public $depends = [

        'yii\bootstrap\BootstrapAsset',

    ];

}



Thanks

I believe that most "proper" way to do this would be to override AssetBundle::registerAssetFiles():




class MyTestAsset extends AssetBundle

{

...

	public function registerAssetFiles($view)

	{

		parent::registerAssetFiles($view);

		

		$view->registerJsFile('@web/js/your-file.js');

	}

}



i know other ways but all of them require creating additional classes.

are there no other ways which would not require creating additional classes?

Well, you at least need one asset bundle class - it is where you add the overridden registerAssetFiles() method. All this in a single class:




use yii\web\AssetBundle;


class MyTestAsset extends AssetBundle

{

	public $sourcePath = '@bower/myplugin';


	public $css = [

		'myplugin.min.css'

	];

	public $js = [

		'myplugin.min.js',

	];

	public $depends = [

		'yii\bootstrap\BootstrapAsset',

	];

	

	// additional files from @web

	public $webJs = [

		'extra.js',

	];

	public $webCss = [

		'extra.css'

	];

	

	public function registerAssetFiles($view)

	{

		parent::registerAssetFiles($view);


		foreach ($this->webJs as $js) {

			$view->registerJsFile('@web/js/' . $js, $this->jsOptions);

		}

		foreach ($this->webCss as $css) {

			$view->registerCssFile('@web/css/' . $css, $this->cssOptions);

		}

	}

}