问题描述
我想全局配置资产转储我的 JS 文件的输出目录.目前,他们总是去web/js/*
.我想将其更改为 web/js/compiled/*
.
I'd like to globally configure the output dir of where assetic dumps my JS files. Currently, they always go to web/js/*
. I want to change this to web/js/compiled/*
.
可以在每个文件级别指定此项:http://symfony.com/doc/2.0/cookbook/assetic/asset_management.html#dumping-asset-files
It's possible to specify this at a per-file level: http://symfony.com/doc/2.0/cookbook/assetic/asset_management.html#dumping-asset-files
似乎找不到在我的 Symfony 应用程序中全局设置此设置的方法.我缺少任何配置参数吗?
Can't seem to find a way to set this globally across my Symfony app. Any config parameter I'm missing?
更新
找到一个名为 write_to
的资产配置参数.在 config.yml
中设置此项会导致命令行 assetic:dump
将文件转储到新目录,但在 twig 文件中,asset_url
变量仍然存在指向原始路径.
Found an assetic config parameter called write_to
. Setting this in config.yml
causes the command line assetic:dump
to dump files to the new dir, but within twig files the asset_url
var still points to the original path.
推荐答案
您应该使用 write_to 属性.
在我的配置中,例如我使用
in my configuration for exemple I use
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: %kernel.debug%
read_from: %kernel.root_dir%/Resources/views/
write_to: %kernel.root_dir%/../web/static/
你的输出字符串从哪里开始write_to
Your ouput string start where ends write_to
例如
{% javascripts filter="closure" output='js/main.js'
...
{% stylesheets filter='compass,?cssrewrite'
'default/static/sass/screen.scss'
output='css/screen.css'
%}
两者都会分别放在/web/static/js/main.js和 /web/static/css/screen.css
both will placed respectively in /web/static/js/main.jsand /web/static/css/screen.css
assets_base_urls 用于指定用于从 http 和 ssl (https) 页面引用的资产的基本 URL.
assets_base_urls is used to specify base URL's to be used for assets referenced from http and ssl (https) pages.
!! assets_base_urls
也被 {% images %}
用作 output
值之前的根,但是 {% images %}
在渲染 html 时不考虑 write_to
(仅在转储时)所以最好不要使用 write_to
而只依赖 write_to
代码>输出代码>值.在 我在 stackoverflow 上的另一篇文章中了解更多信息 和 AsseticBundle 的 github 上的这篇帖子.
!! assets_base_urls
is also used by {% images %}
as the root before output
value, but {% images %}
doesn't consider write_to
when rendering html (only when dumping) so better not using write_to
and rely only on output
value. More about it in my other post on stackoverflow and in this post on AsseticBundle's github.
这篇关于在 Symfony2 中为 Assetic 配置输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!