yii2中的资产包生成空文件

时间:2014-02-14 14:07:48

标签: php yii2

资产包生成空的JavaScript和CSS文件

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' => '',
    ],
];

然后在控制台

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

并在配置

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

CSS和JavaScript文件位于目录中:

  

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

  

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

Bundle生成空箱:

  

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

我做错了什么?

2 个答案:

答案 0 :(得分:1)

在config.php中,尝试配置组件' assetManager'像下面的LOC一样:

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

答案 1 :(得分:0)

您应该设置别名@web和@webroot,因为此文件将在控制台脚本中使用。然后使用别名来设置basePath和baseUrl参数

查看更多信息https://www.yiiframework.com/doc/guide/2.0/en/structure-assets