25

Asset bundle generate empty JavaScript and CSS files

namespace frontend\assets;

return [

    'bundles' => [
        'frontend\assets\AppAsset',

    ],

    'targets' => [
        'frontend\assets\AppAsset' => [
            'basePath' => 'e:/path/yii2.loc/www',
            'baseUrl' => '',
            'js' => 'js/{ts}.js',
            'css' => 'css/{ts}.css',
        ],
    ],

    'assetManager' => [
        'basePath' => 'e:/path/yii2.loc/www/assets',
        'baseUrl' => '',
    ],
];

config.php

return [

    'bundles' => [
        'frontend\assets\AppAsset',
    ],

    'targets' => [
        'frontend\assets\AppAsset' => [
            'basePath' => 'e:/path/yii2.loc/www',
            'baseUrl' => '',
            'js' => 'cache/{ts}.js',
            'css' => 'cache/{ts}.css',
        ],
    ],

    'assetManager' => [
        'basePath' => 'e:/path/yii2.loc/www/assets',
        'baseUrl' => '',
    ],
];

Then in console

yii asset e:\path\config.php e:\path\compressed.php
//compresed.php it's result file with name of compressed files

And in config

'assetManager' => [
    'bundles' => require dirname(__DIR__) . '/assets/compressed.php',
],

CSS and JavaScript files are in a directory:

e:/path/yii2.loc/www/css

And

e:/path/yii2.loc/www/js

Bundle generate empties to:

e:/path/yii2.loc/www/cache/css and e:/path/yii2.loc/www/cache/js

What did I do wrong?

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Vitaliy
  • 331
  • 4
  • 14

2 Answers2

1

Inside your config.php, try to config component 'assetManager' like as the following LOCs:

'components' => [
    'assetManager' => [
        'class' => 'yii\web\AssetManager', 
        'basePath' => 'YOUR_BASE_PATH' 
    ],  
],
0

You should set aliases @web and @webroot, because of this file will be use in console script. Then use aliases for setting basePath and baseUrl parameters

Check out for more info https://www.yiiframework.com/doc/guide/2.0/en/structure-assets

tansky
  • 11
  • 1