Symfony2 and Assetic - cssrewrite works perfectly for dev, not for prod

霸气de小男生 提交于 2019-12-04 11:13:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!