Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postcss-loader Autoprefixer not working with Webpack 3

I'm attempting to use a series of loaders to extract all the SCSS files into one file with ExtractTextPlugin. Within the series of loaders I have, I'm using the autoprefixer plugin that is used within postcss-loader. However, nothing seems to be getting prefixed!

My webpack config is as follows:

webpack.config.js

const path = require('path');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const config = {
  context: __dirname,
  entry: {
    app: [
      path.resolve(entrypath),
    ],
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            'sass-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: () => [autoprefixer()]
              }
            }
          ]
        }),
      },
    ],
  },
  output: {
    path: path.join(__dirname, '../app/assets/javascripts/generated/'),
  },
  plugins: [
    new ExtractTextPlugin({
      filename: 'compiled-draft-document-scss.css',
      allChunks: true
    }),
  ],
};

module.exports = config;

My output seems all good with the exception that none of the prefixes are added. Below are the relevant versions of packages I am using:

"extract-text-webpack-plugin": "3.0.1",
"webpack": "^3.1.0",
"style-loader": "^0.19.0",
"css-loader": "^0.23.1",
"moment": "^2.11.1",
"postcss-loader": "^0.10.1",
"sass-loader": "^6.0.6",
like image 440
Xenyal Avatar asked Dec 05 '17 16:12

Xenyal


1 Answers

From postcss-loader README:

Use it after css-loader and style-loader, but before other preprocessor loaders like e.g. sass|less|stylus-loader.

So your loader chain should be:

[
  'css-loader',
  {
    loader: 'postcss-loader',
    options: {
      plugins: () => [autoprefixer()]
    }
  },
  'sass-loader'    
]
like image 77
KyTrol Avatar answered Sep 30 '22 19:09

KyTrol