Skip to content

Instantly share code, notes, and snippets.

@joshuacerbito
Created October 25, 2018 09:14
Show Gist options
  • Save joshuacerbito/b8a02f036fc03a623277759097c534d2 to your computer and use it in GitHub Desktop.
Save joshuacerbito/b8a02f036fc03a623277759097c534d2 to your computer and use it in GitHub Desktop.
Sample Webpack Config for React JS Development
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const devMode = process.env.NODE_ENV !== 'production'
const config = {
entry: './src/index.js',
output: {
// `path` is the folder where Webpack will place your bundles
path: path.resolve(__dirname, 'dist'),
// `filename` provides a template for naming your bundles (remember to use `[name]`)
filename: '[name].bundle.js',
// `chunkFilename` provides a tem
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.s?[ac]ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
],
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: './public/index.html',
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
}),
],
}
module.exports = config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment