【问题标题】:Symfony assetic with named assets, dumped twice in prod environment?带有命名资产的 Symfony 资产,在 prod 环境中被转储了两次?
【发布时间】:2014-03-28 19:09:48
【问题描述】:

在恕我直言,资产管理是最难理解的部分,即使在使用 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]

使用命名资产:

{% 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

是否有任何理由在 prod 环境中生成两个相同的文件?

【问题讨论】:

  • 这对调试也有好处,尝试使用--no-debug,不确定但应该会阻止生成/assets文件夹...但只是猜测。

标签: symfony assets symfony-2.3


【解决方案1】:

第一个文件assetic/mybundle_front_js.js 是配置命名资产的结果文件。第二个文件是模板内资产块使用的结果文件。

如果您要在资产块中使用两个资产:

{% block javascripts %}
    {% javascripts
        "@mybundle_front_js"
        "@whateveer" %}
        <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

您最终会在assetic/ 文件夹中得到两个命名资产文件,在js/ 文件夹中得到一个包含这两个文件内容的文件。

猜猜为什么assetic/ 文件夹中还有文件:您可以配置命名资产并干净地引用它们,而无需使用{% javascripts %} 块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 2019-08-06
    • 1970-01-01
    相关资源
    最近更新 更多