R
R
ralo2017-03-07 13:38:33
webpack
ralo, 2017-03-07 13:38:33

Webpack SASS Autoprefixer?

Dear Webpack experts, tell me how to include autoprefixer

const webpack = require('webpack');
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const extractSass = new ExtractTextPlugin({
  filename: "./assets/css/styles.css"
});


module.exports = {
  
  entry: {
    app: './src/js/app.js',
    about: './src/js/about.js',
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: './assets/js/[name].js',
    library: '[name]'
  },
  
  module: {
    rules: [
      {
        test: /\.sass|scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'sass-loader'],
          publicPath: './dist/assets/css/'
        })
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['env'],
          plugins: ['transform-runtime']
        }
      }
    ]
  },
  
  devtool: "cheap-eval-source-map",
  
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    compress: true,
    port: 9000,
    stats: 'errors-only',
    open: true
  },
  
  plugins: [
    
    extractSass,
    
    new HtmlWebpackPlugin({
      title: 'My App',
      filename: 'index.html',
      template: './src/index.html',
      hash: true,
      // minify: { collapseWhitespace: true },
      chunks: ['app', 'common']
    }),
    new HtmlWebpackPlugin({
      title: 'About',
      filename: 'about.html',
      template: './src/about.html',
      hash: true,
      // minify: { collapseWhitespace: true },
      chunks: ['about', 'common']
    }),
    
    new ExtractTextPlugin("./assets/css/styles.css"),
    
    new webpack.optimize.CommonsChunkPlugin({
      name: 'common',
      chunks: ['about', 'app']
    }),
    
    // new UglifyJSPlugin(),
  ]
}

The solution I found was
created with a number of webpack.config.js file postcss.config.js
added to it
module.exports = {
  plugins: [
    require('autoprefixer')
  ]
}

and added postcss-loader
use: ['css-loader', 'postcss-loader', 'sass-loader'],

can also be added to package.json to support the required prefixes
"browserslist": [
    "> 1%",
    "last 2 versions"
  ]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
ITZver, 2017-09-16
@ITZver

I did something like this.
Configuring Autoprefixer for Webpack

V
Vic Shostak, 2017-12-15
@vikkyshostak

For my (and not so) Django/Flask projects, I use this set of configs:
https://gist.github.com/koddr/3d8be47815dce570fcf2...
Includes: Autoprefixer, PostCSS, SCSS, Vue.js and Babel . Configs are tested and used in production, like a skeleton, to quickly deploy the environment.

S
sutkin main, 2017-03-07
@kapko

module: {
rules: [
{
test: /\.sass|scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader'],
publicPath : './dist/assets/css/'
})
},
{
test: /\.css/,
loader: 'css!style!autoprefixer!?browsers=last 12 versions',
},
{
test: /\.js $/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['env'],
plugins: ['transform-runtime']
}
}
]
docs for this
https://github.com/passy/autoprefixer-loader

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question