简体   繁体   中英

How can I use Autoprefixer with Symfony2

I'm trying to integrate Autoprefixer in a Symfony2 (with Assetic) workflow. My first thought was that Assetic already provided support for it as a filter (like UglifyCSS and others), so I tried this:

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

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.

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. 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?

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.

So instead of autoprefixer , the solution was installing autoprefixer-cli , an unofficial binary which addresses "legacy" code.

sudo npm install autoprefixer-cli --save

And then pointing to that binary in the parameters.yml . In my case:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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