【发布时间】:2014-02-04 23:27:34
【问题描述】:
使用 Symfony 和 Assetic,我无法在我的 prod 环境中正确地“转储”css 图像。 他们继续链接回 web/bundle/...etc.. 位置。
我有一个非常基本的 cssrewrite 设置:
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
filters:
cssrewrite:
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
我的模板:
{% stylesheets 'bundles/<my bundle>/css/style.css' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
我有 app.php 的 prod 版本,但 debug false:
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$apcLoader = new ApcClassLoader('sf2', $loader);
$loader->unregister();
$apcLoader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
我已经完成了:
应用程序/控制台资产:安装 --symlink
一切正常
然后我清除产品缓存
好的
应用程序/控制台资产:转储 --env=prod
我的 css 和 js 使用预期的文件名复制出来,但是我的 css 中仍然出现 url('../../bundle/..etc../images/bg.png');
在符号链接版本中,css 为:url('../images/bg.png');
所以一定和资产有关。
我期望“转储”的 css 包含像 url('../images/bg.png'); 之类的链接;
并将图像本身复制到 web/images/123abc.png
我应该从资产中得到这个吗?如果是,我做错了什么?
谢谢,提前。
【问题讨论】:
-
看起来你需要在你的css中有相对链接,否则assetic不会重写图像。谁能确认这是否是我所期望的?
-
我已经查看了文档,它确实声明是这种情况。我很认真地为自己没有早点看到而打脸。
标签: css symfony rewrite assetic