只有转储文件的资产

Assetic assets with only dumped files

我们已经开始使用 Bower(通过 SpBower)来管理我们的 js 和 css 库,然后才意识到无法在我们当前的产品服务器上安装 Bower。

想法不是在生产服务器上生成文件,而是将生产文件转储到开发环境并上传这些转储文件。但是即使在 prod 模式下,Assetic 也在寻找源文件并且 bower 注册了这些供应商文件,所以 Assetic 抛出了这个异常

(Twig_Error_Syntax(code: 0): An exception has been thrown during the compilation 
of a template (\"There is no \"jquery_js\" asset.\")

其中jquery_js是这样在Bower注册后调用的

    {% javascripts output='js/vendor-1.js'
        '@jquery_js'
        '@jquery_ui_js'
        '@chartjs_js'
        '@Chart_StackedBar_js_js' %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}

有没有办法告诉 assetic 忽略资产 (jquery_js, jquery_ui_js...) 只查看输出文件 (vendor-1.js)?我在 Symfony2 食谱中找不到任何内容。


下面是 config.yml

中的 Assectic 和 Sp Bower 部分
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ProjectBundle ]
    filters:
        cssrewrite: ~

sp_bower:
    assetic:
        nest_dependencies: false
    bundles:
        ProjectBundle:
            asset_dir: ../../public/vendor
            cache:
                id: ~
                directory: ../../public/vendor/cache

并且在config_dev.yml

assetic:
    use_controller: false

以及bower.json文件的内容

{
    "name": "ProjectBundle",
    "dependencies": {
        "jquery": "~2.0",
        "jquery.countdown": "~2.0", 
        "jquery-ui": "~1.11",
        "bootstrap": "~3.0",
        ...
    }
}

我找到了解决方法,虽然不是很好,但可以解决我们的问题。

想法是仅在开发环境中使用 sp_bower,以便仅将其放在 config_dev.yml 中,并在生产环境中手动指定命名资产,因此在 config_prod.yml.[=16 中=]

因为我们不会在 prod 上生成输出文件(但使用上传的文件),所以我们实际上不必输入正确的源文件路径,我们甚至可以使用伪造的 js 文件(例如名为 prodDumpAlert.js) 的文件包含例如解释正在发生的事情的警报。

所以 config_dev.yml 看起来像这样 :

imports:
    - { resource: config.yml }

assetic:
    assets:
        jquery_js:
            inputs:
                - '@ProjectBundle/Resources/public/utils/prodDumpAlert.js'
        jquery_ui_js:
            inputs:
                - '@ProjectBundle/Resources/public/utils/prodDumpAlert.js'
        chartjs_js:
            inputs:
                - '@ProjectBundle/Resources/public/utils/prodDumpAlert.js'
...