Search code examples
javascriptyii2assetsassetbundle

Javascript in Yii2 AssetBundle is not published on update


I have a quite simple AssetBundle:

use yii\web\AssetBundle;

/**
 * ImagizerAsset
 */
class ImagizerAsset extends AssetBundle
{
    public $sourcePath = '@app/components/widgets/imagizer/assets';

    public $css = [
        'css/imagizer.css'
    ];

    public $js = [
        'js/imagizer.js',
    ];

    public $depends = [
        'app\assets\BowerCropperAsset'
    ];
}

If I change the JavaScript in the bundle, it is not published to the web/asset directory in development mode. I must remove the web/asset directory every time to have an up to date version in it. It is very annoying. What should I do?


Solution

  • It's already answered here.

    Add this to your asset bundle:

    public $publishOptions = [
        'forceCopy' => YII_DEBUG,
    ];
    

    For more options and detailed explanation look at linked answer.