Last active
December 13, 2016 18:35
-
-
Save urre/51f4701b10cce2d848adaf21b6e31272 to your computer and use it in GitHub Desktop.
Using Autoprefixer with ExtractTextPlugin with Webpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const autoprefixer = require('autoprefixer'); | |
const postcssImport = require('postcss-import'); | |
const postcssUrl = require('postcss-url'); | |
module.exports = { | |
devtool: 'source-map', | |
entry: ['./src/index'], | |
output: { | |
path: path.join(__dirname, 'public'), | |
filename: 'bundle.js' | |
}, | |
plugins: [ | |
new webpack.optimize.UglifyJsPlugin({ | |
compressor: { | |
warnings: false, | |
}, | |
}), | |
new ExtractTextPlugin("[name].css", { | |
allChunks: true | |
}), | |
new webpack.optimize.OccurrenceOrderPlugin(), | |
new HtmlWebpackPlugin({ | |
template: './src/index.html' | |
}), | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify('production') | |
}) | |
], | |
postcss: function(webpack) { | |
return [ | |
postcssImport({ | |
addDependencyTo: webpack | |
}), | |
postcssUrl(), | |
autoprefixer({ | |
browsers: ['last 2 versions'] | |
}) | |
]; | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.js$/, | |
exclude: /(node_modules)/, | |
loader: 'babel-loader?presets[]=es2015' | |
}, | |
{ | |
test: /\.css$/, | |
loader: ExtractTextPlugin.extract( | |
"style-loader", | |
"css-loader?-autoprefixer!postcss-loader" | |
) | |
}, | |
{ | |
test: /\.html$/, | |
loader: 'raw!html-minify' | |
}, | |
{ | |
test: /\.(jpe?g|png|gif|svg)$/, | |
exclude: /(node_modules)/, | |
loader: 'url-loader?limit=10000' | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment