2

我希望assetic将压缩的js和css输出到这样的东西: v2.3.1/css/whatever.css

目前,这就是我转储我的 css 和 js 以进行生产的方式:$ php app/console assetic:dump --env=prod --no-debug. 但是他们被转储到 css/ 和 js/ 中,没有版本。

我读过这个,但它似乎只指图像,而不是 css/js。

这样做的一个重要原因是缓存破坏/无效。

4

3 回答 3

3

是的,已知问题......在我们的生产工作流程中,我们最终在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')));
}

如您所见,我们定义了控制台命令,它在安装和转储 Symfony 的资产后将资产安装到 web 文件夹中。在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);
于 2012-08-10T05:44:24.713 回答
1

嗬,这是一个很大的 Symfony2 错误!我不确定是否有人举报!

我的解决方案是在 Nginx 配置中添加一个别名,但你的是 def。更干净,更好。

于 2012-08-11T10:51:24.030 回答
0

我的解决方法是在 .htaccess 文件中创建一个 rewriteRule 以提供真实文件,但接受带有版本号的完整 url。像这样的东西...

应用程序/配置/config.yml

[...]
engines: ['twig']
assets_version: 20140523  # numeric version
assets_version_format: "assets-%%2$s/%%1$s"
[...]

网页/.htaccess

[...]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^assets-([0-9]*)/(.*)$ ./$2 [L]
[...]
于 2014-05-26T16:29:48.080 回答