我想assetic输出压缩js和css来是这样的: v2.3.1/css/whatever.css
如何将资产版本预先添加到css和js?
目前,我这是怎么甩我的CSS和JS生产:$ php app/console assetic:dump --env=prod --no-debug
。但是他们被转储到css /和js /中,没有版本。
我已阅读this但它似乎只涉及图像,而不是css/js。
这样做的一个重要原因是缓存清除/无效。
我想assetic输出压缩js和css来是这样的: v2.3.1/css/whatever.css
如何将资产版本预先添加到css和js?
目前,我这是怎么甩我的CSS和JS生产:$ php app/console assetic:dump --env=prod --no-debug
。但是他们被转储到css /和js /中,没有版本。
我已阅读this但它似乎只涉及图像,而不是css/js。
这样做的一个重要原因是缓存清除/无效。
是的,已知的问题......在我们的生产流程,我们在bin/vendors
脚本结束了这样的块:
if (in_array('--env=dev', $argv)) {
system(sprintf('%s %s assets:install --symlink %s', $interpreter, escapeshellarg($rootDir . '/app/console'), escapeshellarg($rootDir . '/web/')));
system(sprintf('%s %s assetic:dump --env=dev', $interpreter, escapeshellarg($rootDir . '/app/console')));
system(sprintf('%s %s myVendor:assets:install --symlink ', $interpreter, escapeshellarg($rootDir . '/app/console')));
} else {
system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir . '/app/console'), escapeshellarg($rootDir . '/web/')));
system(sprintf('%s %s assetic:dump --env=prod --no-debug', $interpreter, escapeshellarg($rootDir . '/app/console')));
system(sprintf('%s %s myVendor:assets:install ', $interpreter, escapeshellarg($rootDir . '/app/console')));
}
正如你所看到的,我们定义控制台命令,安装后资产注入Web文件夹安装和倾销Symfony的资产。在MyVendorCommand
脚本中我们做这样的事情:
$version = $this->getContainer()->getParameter('your_version_parameter');
$assetsInstallCommand = $this->getApplication()->find('assets:install');
$commandOptions = $input->getOptions();
$assetsInstallArguments = array(
'command' => 'assets:install',
'target' => 'web/version-' . $version,
'--symlink' => $commandOptions['symlink']
);
$assetsInstallInput = new ArrayInput($assetsInstallArguments);
$returnCode = $assetsInstallCommand->run($assetsInstallInput, $output);
何,它的一个很大的Symfony2错误!我不确定有谁报告它!
我的解决方案是在Nginx配置中添加一个别名,但你的是def。清洁剂&更好。
我的解决方法是在.htaccess文件中创建一个rewriteRule,以便为真实文件提供服务,但接受带有版本号的完整url。事情是这样的......
[...]
engines: ['twig']
assets_version: 20140523 # numeric version
assets_version_format: "assets-%%2$s/%%1$s"
[...]
[...]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^assets-([0-9]*)/(.*)$ ./$2 [L]
[...]
哦,我明白了。那么我对sf2的内部知识并不了解,而且我正在使用v2.1,因此bin /供应商不在了。但是你提出了一个想法,并且它的工作原理:我将符号链接创建部分添加到了我的部署脚本('vXXX/css - > css'和'vXXX/js - > js')。再次感谢! =) – ChocoDeveloper 2012-08-10 08:10:07