Php 如何将资产版本前置到css和js?
我希望assetic将压缩的js和css输出到如下内容:Php 如何将资产版本前置到css和js?,php,caching,symfony,twig,assetic,Php,Caching,Symfony,Twig,Assetic,我希望assetic将压缩的js和css输出到如下内容: v2.3.1/css/whatever.css 目前,这就是我为生产转储css和js的方式:$php app/console assetic:dump--env=prod--no debug。但是它们被转储到css/和js/中,没有版本 我读过,但它似乎只是指图像,而不是css/js 这样做的一个重要原因是缓存破坏/失效。是的,已知问题。。。在我们的生产工作流程中,我们在bin/vendors脚本中得到了这样的块: if (in_ar
v2.3.1/css/whatever.css
目前,这就是我为生产转储css和js的方式:$php app/console assetic:dump--env=prod--no debug
。但是它们被转储到css/和js/中,没有版本
我读过,但它似乎只是指图像,而不是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')));
}
如您所见,我们定义了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);
是的,已知问题。。。在我们的生产工作流程中,我们在
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')));
}
如您所见,我们定义了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);
哦,这是一个大的Symfony2错误!我不确定是否有人报告了此事
我的解决方案是在Nginx配置中添加一个别名,但您的是def。更干净更好。哦,这是一个很大的Symfony2错误!我不确定是否有人报告了此事
我的解决方案是在Nginx配置中添加一个别名,但您的是def。更干净更好。我的解决方法是在.htaccess文件中制定一个重写规则,以便为真实文件提供服务,但接受带有版本号的完整url。像这样的 app/config/config.yml web/.htaccess
[…]
重新启动发动机
重写规则^assets-([0-9]*)/(.*)$./$2[L]
[...]
我的解决方法是在.htaccess文件中制定一个重写规则,以提供真实的文件,但接受带有版本号的完整url。像这样的
app/config/config.yml
web/.htaccess
[…]
重新启动发动机
重写规则^assets-([0-9]*)/(.*)$./$2[L]
[...]
哦,我明白了。我不太了解sf2的内部结构,而且我使用的是v2.1,所以bin/供应商已经不存在了。但是你提出了一个想法,它成功了:我将符号链接创建部分添加到我的部署脚本中(vXXX/css->css
和vXXX/js->js
)。再次感谢!=)哦,我明白了。我不太了解sf2的内部结构,而且我使用的是v2.1,所以bin/供应商已经不存在了。但是你提出了一个想法,它成功了:我将符号链接创建部分添加到我的部署脚本中(vXXX/css->css
和vXXX/js->js
)。再次感谢!=)