简体   繁体   English

如何在Symfony2中使用Autoprefixer

[英]How can I use Autoprefixer with Symfony2

I'm trying to integrate Autoprefixer in a Symfony2 (with Assetic) workflow. 我正在尝试将Autoprefixer集成到Symfony2(带有Assetic)工作流程中。 My first thought was that Assetic already provided support for it as a filter (like UglifyCSS and others), so I tried this: 我的第一个想法是,Assetic已经提供了对它作为过滤器 (如UglifyCSS和其他)的支持,所以我尝试了这个:

    {% stylesheets
        '@PrivateBundle/Resources/public/less/bootstrap/bootstrap.less'
        '@PrivateBundle/Resources/public/less/private.less'

        filter='less,cssrewrite,autoprefixer,?uglifycss' 
    %}
        <link rel="stylesheet" href="{{ asset_url }}">
    {% endstylesheets %}

But it didn't work. 但它没有用。


The only alternative I could find was netzmacht/assetic-autoprefixer , but I couldn't make it work either. 我能找到的唯一选择是netzmacht / assetic-autoprefixer ,但我也无法使其工作。

I installed autoprefixer globally (via sudo npm install -g autoprefixer ), and also installed kriswallsmith/assetic (which I guess is a different assetic that supports Autoprefixer) via composer, but after that I could not find the binary I need for the parameters.yml file. 我全局安装了autoprefixer (通过sudo npm install -g autoprefixer ),并且还通过sudo npm install -g autoprefixer安装了kriswallsmith / assetic (我猜这是支持Autoprefixer的另一种资产),但之后我找不到parameters.yml所需的二进制文件parameters.yml文件。

I read on some github issue that autoprefixer may have changed several times since assetic-autoprefixer was last updated, but I can't find the thread now. 我读了一些github问题,自上次更新assetic-autoprefixer以来autoprefixer可能已经多次更改,但我现在找不到该线程。 There weren't any further comments about that anyway. 无论如何,没有任何进一步的评论。

Is there anything I'm missing or doing wrong? 有什么我遗失或做错了吗? Are there any other ways to use Autoprefixer (or any other similar tool) with Symfony and Assetic? 有没有其他方法可以使用Autoprefixer(或任何其他类似工具)与Symfony和Assetic?

I finally found a solution. 我终于找到了解决方案。 Seems that autoprefixer is no longer a standalone tool, but a plugin for other tools, so the way in which assetic-autoprefixer was trying to use it (with a binary) isn't valid anymore. 似乎autoprefixer不再是一个独立的工具,而是一个其他工具的插件,因此assetic-autoprefixer尝试使用它(使用二进制文件)的方式不再有效。

So instead of autoprefixer , the solution was installing autoprefixer-cli , an unofficial binary which addresses "legacy" code. 因此,解决方案是安装autoprefixer-cli而不是autoprefixer ,这是一个解决“遗留”代码的非官方二进制文件。

sudo npm install autoprefixer-cli --save

And then pointing to that binary in the parameters.yml . 然后指向parameters.yml中的二进制文件。 In my case: 就我而言:

assetic:
    autoprefixer:
        bin: %kernel.root_dir%/../node_modules/autoprefixer-cli/autoprefixer-cli

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM