我想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