问题
I include my CSS with the following code:
{% stylesheets 'bundles/majorproductionssewingdivasite/css/*.css' filter='cssrewrite' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
In dev, this allows me to use image sprites without any problems. The resulting URL to my sprite is:
http://localhost/diva/web/bundles/majorproductionssewingdivasite/images/diva-sprites.jpg
But, in prod, it gets mapped to:
http://localhost/diva/bundles/majorproductionssewingdivasite/images/diva-sprites.jpg
Notice the lack of web directory.
The generated code in the CSS file is as it should be, and all my CSS (both the dev 'chunks' and the finalized prod assetic dump) are at web/css/
. Any ideas as to why the prod environment is skipping the web directory?
EDIT: what's weird is that both dev and prod generate the same URL in the CSS itself:
url('../../bundles/majorproductionssewingdivasite/images/diva-sprites.jpg')
回答1:
Solution is to dump the assets in the prod environment:
$ app/console assetic:dump --env=prod
回答2:
Remember to Clear the Cache
php app/console cache:clear --env=prod --no-debug
berore
php app/console assetic:dump --env=prod --no-debug
回答3:
Also remember to appropriate configure assetic, in your config_prod.yml set as below:
assetic:
use_controller: false
Edit: As said in Symfony docs (actually in chapter refers to dev environment): tell Symfony to stop trying to process these files dynamically
回答4:
In debug mode, Assetic 1.1 also seems to rewrite CSS even when it's not in the {% stylesheets %} tag. So it's worth checking that's there when you turn off debug in production.
来源:https://stackoverflow.com/questions/14073117/symfony2-and-assetic-cssrewrite-works-perfectly-for-dev-not-for-prod