Assets 管理是最难理解恕我直言的部分,即使在 Symfony 玩了一年或更长时间之后。无论如何,我正在试验 named assets :
assets:
mybundle_front_js:
inputs:
- @MeMyBundle/Resources/public/jquery/dist/jquery.js
- @MeMyBundle/Resources/public/bootstrap/js/affix.js
- @MeMyBundle/Resources/public/bootstrap/js/alert.js
- @MeMyBundle/Resources/public/bootstrap/js/button.js
- @MeMyBundle/Resources/public/bootstrap/js/carousel.js
- @MeMyBundle/Resources/public/bootstrap/js/collapse.js
- @MeMyBundle/Resources/public/bootstrap/js/dropdown.js
- @MeMyBundle/Resources/public/bootstrap/js/modal.js
- @MeMyBundle/Resources/public/bootstrap/js/tooltip.js
- @MeMyBundle/Resources/public/bootstrap/js/popover.js
- @MeMyBundle/Resources/public/bootstrap/js/scrollspy.js
- @MeMyBundle/Resources/public/bootstrap/js/tab.js
- @MeMyBundle/Resources/public/bootstrap/js/transition.js
filters: [?uglifyjs2]
使用命名 Assets :
{% block javascripts %}
{% javascripts
"@mybundle_front_js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
倾倒他们:
php app/console cache:clear --env=prod
php app/console assetic:dump --env=prod
结果是两个文件,大小相同,内容相同:
%kernel.root_dir%/../web/assetic/mybundle_front_js.js
%kernel.root_dir%/../web/js/055a364.js
是否有任何理由在生产环境中生成两个相同的文件?
最佳答案
第一个文件assetic/mybundle_front_js.js
是配置命名 Assets 的结果文件。第二个文件是从模板内的 Assets 块使用的结果文件。
如果您要在 Assets 区块中使用两个 Assets :
{% block javascripts %}
{% javascripts
"@mybundle_front_js"
"@whateveer" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
您最终会在
assetic/
中得到两个命名的 Assets 文件。文件夹,以及 js/
中的一个文件包含两个文件内容的文件夹。猜测为什么
assetic/
中还有文件文件夹:您可以配置命名 Assets 并干净地引用它们,而无需使用 {% javascripts %}
堵塞。
关于带有命名 Assets 的 Symfony Assets ,在生产环境中转储两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22721231/