Skip to content

Instantly share code, notes, and snippets.

@ciaoben
Last active October 16, 2017 14:08
Show Gist options
  • Save ciaoben/862321966666f3082ce60b3316ff190f to your computer and use it in GitHub Desktop.
Save ciaoben/862321966666f3082ce60b3316ff190f to your computer and use it in GitHub Desktop.
example webpack
const webpack = require('webpack')
var path = require('path')
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
devtool: 'cheap-source-map',
entry: ['./index.js'],
watchOptions: {
ignored: /node_modules/
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
exclude: /node_modules/,
use: [{ loader: 'babel-loader' }]
},
{
test: /(\.scss$|\.css$|\.sass$)/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]'
}
},
{ loader: 'sass-loader' }
]
}
]
},
resolve: {
modules: ['node_modules', 'src'],
extensions: ['.js', '.jsx'],
alias: {
Globals: path.resolve(__dirname, 'globals/')
}
},
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js',
chunkFilename: '[name].bundle.js'
},
devServer: {
contentBase: './dist',
host: '0.0.0.0',
watchOptions: {
ignored: /node_modules/
},
noInfo: true,
historyApiFallback: true
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
umd: 'react'
}
},
performance: {
hints: false
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static'
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment