如何使用丢失,autoprefixer和postcss灵活性?

时间:2016-04-04 14:19:58

标签: webpack postcss autoprefixer

我想知道autoprefixer中我们应该使用lostpostcssflexibilitywebpack的顺序?

1 个答案:

答案 0 :(得分:1)

Here's a basic example (prefixing through postcss, applying precss plugin etc.).

webpack 1

const autoprefixer = require('autoprefixer');
const precss = require('precss');

module.exports = {
  module: {
    loaders: [
      {
        test: /\.css$/,
        loaders: ['style', 'css', 'postcss'],
      },
    ],
  },
  // PostCSS plugins go here
  postcss: function () {
    return [autoprefixer, precss];
  },
};

webpack 2

module: {
  rules: [
    {
      test: /\.css$/,
      use: [
        'style-loader',
        'css-loader',
        {
          loader: 'postcss-loader',
          options: {
            ident: 'postcss', // Needed for now
            plugins: function () {
              // Set up plugins here
              return [
                require('autoprefixer'),
                require('precss'),
              ];
            },
          },
        },
      ],
    },
  ],
},

Another way would be to push the plugins to postcss.config.js as instructed in the postcss-loader documentation. It is more difficult to compose that, though.

Source.