Skip to content

Instantly share code, notes, and snippets.

@urre
Last active December 13, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urre/51f4701b10cce2d848adaf21b6e31272 to your computer and use it in GitHub Desktop.
Save urre/51f4701b10cce2d848adaf21b6e31272 to your computer and use it in GitHub Desktop.
Using Autoprefixer with ExtractTextPlugin with Webpack
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