Assetic Symfony2 less +压缩过滤器

时间:2013-01-05 10:03:19

标签: symfony filter compression less assetic

有没有办法让资产自动编译压缩.less文件?

我试过这个配置:

assetic:
debug:          "%kernel.debug%"
use_controller: true
bundles:        ['BloggerBlogBundle', "FOSCommentBundle"]
#java: /usr/bin/java
filters:
    cssrewrite: ~
    less:
      node: /home/igor/nvm/v0.8.16/bin/node
      node_paths: [/home/igor/nvm/bin/node_modules]
      apply_to: "\.less$"
    yui_css:
      jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
      apply_to: "\.css$|\.less"

但这导致 .css 文件被压缩, .less 文件被编译。 我无法做到这两点:编译然后压缩我的.less文件。

1 个答案:

答案 0 :(得分:9)

这是我的配置和twig代码,用于同时编译+压缩.less文件:

config.yml

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    java: %java_path%
    filters:
        less:
            node:       %node_base_path%
            node_paths: [%node_lib_path%, %node_modules_path%]
        cssrewrite: ~
        yui_css:
            jar: %kernel.root_dir%%jar_file%
        yui_js:
            jar: %kernel.root_dir%%jar_file%

在我的树枝上:

{% block stylesheets %}
    {% stylesheets
        '@MyBundle/Resources/public/css/event.less'
        'css/colorpicker.css'
        filter='less,?yui_css'
        output='build/event_layout_2cols.css'
    %}
        <link href="{{ asset_url }}" rel="stylesheet" media="screen" />
    {% endstylesheets %}
{% endblock %}

这是编译和压缩的命令:

./app/console assetic:dump --env=prod --no-debug

希望有所帮助!