I tried to follow the instructions in the guide, but I got an error.
http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#combining-and-compressing-assets
$ yii asset assets.php config/assets-prod.php
Loading configuration from 'assets.php'...
Collecting source bundles information...
Creating output bundle 'all':
Compressing JavaScript files...
PHP Warning 'yii\base\ErrorException' with message 'file_put_contents(/cygdrive/c/Users/Chloe/workspace/xxxxxx/web/assets/js/all-temp.js.tmp): failed to open stream: No such file or directory'
in /cygdrive/c/Users/Chloe/workspace/xxxxxx/vendor/yiisoft/yii2/console/controllers/AssetController.php:545
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'file_put_conten...', '/cygdrive/c/Use...', 545, Array)
#1 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/controllers/AssetController.php(545): file_put_contents('/cygdrive/c/Use...', '/*** BEGIN FILE...')
#2 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/controllers/AssetController.php(487): yii\console\controllers\AssetController->combineJsFiles(Array, '/cygdrive/c/Use...')
#3 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/controllers/AssetController.php(343): yii\console\controllers\AssetController->compressJsFiles(Array, '/cygdrive/c/Use...')
#4 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/controllers/AssetController.php(182): yii\console\controllers\AssetController->buildTarget(Object(yii\web\AssetBundle), 'js', Array)
#5 [internal function]: yii\console\controllers\AssetController->actionCompress('assets.php', 'config/assets-p...')
#6 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#7 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#8 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->runAction('', Array)
#9 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAction('', Array)
#10 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/Application.php(161): yii\base\Module->runAction('asset', Array)
#11 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/console/Application.php(137): yii\console\Application->runAction('asset', Array)
#12 /cygdrive/c/Users/Chloe/workspace/xxxxx/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))
#13 /cygdrive/c/Users/Chloe/workspace/xxxxx/yii(23): yii\base\Application->run()
#14 {main}
This was the closest I've gotten:
Loading configuration from 'assets.php'...
Collecting source bundles information...
Creating output bundle 'all':
Compressing JavaScript files...
ERROR - Cannot read: \cygdrive\c\Users\Chloe\workspace\xxxxx\web\assets\all-temp.js.tmp
1 error(s), 0 warning(s)
Error: Unable to compress JavaScript files into '/cygdrive/c/Users/Chloe/workspace/xxxxx/web/assets/all-temp.js'.
This is my assets.php
file
assets.php
Yii::setAlias('@webroot', __DIR__ . '/web');
Yii::setAlias('@web', '/');
return [
// Adjust command/callback for JavaScript files compressing:
'jsCompressor' => 'java -jar compiler.jar --js {from} --js_output_file {to}',
// Adjust command/callback for CSS files compressing:
'cssCompressor' => 'java -jar yuicompressor.jar --type css {from} -o {to}',
// The list of asset bundles to compress:
'bundles' => [
'app\assets\AppAsset',
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
],
// Asset bundle for compression output:
'targets' => [
'all' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets',
'js' => 'js/all-{hash}.js', # also without js/
'css' => 'css/all-{hash}.css', # also without css/
],
],
// Asset manager configuration:
'assetManager' => [
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets',
],
];