Skip to content

Instantly share code, notes, and snippets.

@0xAnon101
Created September 27, 2018 12:38
Show Gist options
  • Save 0xAnon101/67aaf27fa1a7cac3c93f9c3f2bf95bb8 to your computer and use it in GitHub Desktop.
Save 0xAnon101/67aaf27fa1a7cac3c93f9c3f2bf95bb8 to your computer and use it in GitHub Desktop.
final webpack.config.js boilerplate
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const miniCssPlugin = new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css',
})
const htmlPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
})
module.exports = (env,argv) => {
return {
optimization: {
nodeEnv: argv.mode
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
argv.mode =='development' ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
localIdentName: "[name]_[local]_[hash:base64:5]",
}
},
'sass-loader'
]
}
]
},
plugins: [htmlPlugin,miniCssPlugin]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment