【问题标题】:Install vendor resources in web directory在 web 目录中安装供应商资源
【发布时间】:2013-05-17 10:50:55
【问题描述】:

我在 Resources 的捆绑包中有一个名为 vendor 的目录,其中包含 JavaScript 库等。其中一些供应商包含图像。

我可以使用以下资产导入 css/less/js 文件:

assetic:
    assets:
        flot:
            inputs:
                - @MyBundle/Resources/vendor/flot/jquery.flot.js
                - @MyBundle/Resources/vendor/flot/jquery.flot.time.js
            filters:
                - ?yui_js

但是如果供应商包含图像,我不知道如何将它们放入web/ 目录。

我不想手动对它们进行符号链接。

【问题讨论】:

    标签: symfony assetic


    【解决方案1】:

    Assetic 的资产集合,如

    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 
    

    还可以包含图像。但你必须一一指定它们

    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 选项可防止assetic 为每个包中的每个文件创建调试文件。用于生产系统或如果您有其他调试方式(即很棒的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 %}
    

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 2015-03-02
      • 2017-01-11
      • 1970-01-01
      相关资源
      最近更新 更多