在 web 目录中安装供应商资源 [英] Install vendor resources in web directory
问题描述
我的 Resources
包中有一个名为 vendor
的目录,其中包含 JavaScript 库等.其中一些供应商包含图像.
I have in my bundle in Resources
a directory called vendor
which contains JavaScript libraries, etc. Some of those vendors contain images.
我可以使用以下资源导入 css/less/js 文件:
I can import css/less/js files using assets with:
assetic:
assets:
flot:
inputs:
- @MyBundle/Resources/vendor/flot/jquery.flot.js
- @MyBundle/Resources/vendor/flot/jquery.flot.time.js
filters:
- ?yui_js
但是,如果供应商包含图像,我不知道如何将它们放入 web/
目录.
However if vendor contains images, I have no idea, how to put them into web/
directory.
我不想手动符号链接它们.
I'd rather not symlink them manually.
推荐答案
Assetic 的资产集合如
Assetic's asset collections like
assetic:
assets:
collection_name:
inputs:
- ...
output:
- desired_filename # relative to assetic.output_path
filters:
- ?lessphp # scss, optipng, jpegoptim ... whatever
# the ? (question mark) prevents the
# filter to be applied in dev mode
也可以包含图像.但是你必须一一指定
can also contain images. but you have to specify them one by one
assetic:
assets:
[...]
my_image:
inputs:
- /path/to/image/image.png
output:
- images/smushed_image.png
filters:
- optipng
my__second_image:
inputs:
- /path/to/image/image2.jpg
output:
- images/smushed_image2.jpg
filters:
- jpegoptim
然后使用 assetic:dump 命令将它们写入(并编译/粉碎)到您的 Web 文件夹中.--no-debug 选项可防止资产为每个包中的每个文件创建调试文件.用于生产系统或如果您有其他调试方式(即很棒的 源地图 )
Then use the assetic:dump command to have them written ( and compiled / smushed ) to your web folder. The --no-debug option prevents assetic from creating debug files for every single file in every package. Use for production systems or if you have another way of debugging ( i.e. the awesome Source Maps )
app/console assetic:dump --no-debug
使用这样的包:
{% stylesheets '@collection_name' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
或
{% image '@my_image' %}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}
这篇关于在 web 目录中安装供应商资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!