Created
February 17, 2017 14:10
-
-
Save faizalpribadi/e37fe39fefad8fc395b379cb34f69837 to your computer and use it in GitHub Desktop.
Webpack2 Configuration With Hot Module Plugin
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
// This configuration for React - Redux Project | |
// With hot reloaded by react-hot-loader | |
const path = require('path'); | |
const webpack = require('webpack'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const nodeEnv = process.env.NODE_ENV ? 'production' : 'development'; | |
const isProd = nodeEnv === 'production'; | |
const config = { | |
cache: true, | |
context: path.resolve(__dirname, 'src'), | |
entry: [ | |
'react-hot-loader/patch', | |
'webpack-dev-server/client?http://localhost:8080', | |
'webpack/hot/only-dev-server', | |
'./index.js' | |
], | |
output: { | |
path: __dirname + '/dist', | |
filename: 'bundle.js' | |
}, | |
module: { | |
rules: [{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
use: [{ | |
loader: 'babel-loader', | |
options: { | |
presets: [ | |
["es2015", { "modules": false }], "react" | |
] | |
} | |
}] | |
}] | |
}, | |
devtool: 'eval', | |
plugins: [ | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { | |
warnings: false, | |
screw_ie8: true, | |
conditionals: true, | |
unused: true, | |
comparisons: true, | |
sequences: true, | |
dead_code: true, | |
evaluate: true, | |
if_return: true, | |
join_vars: true, | |
}, | |
output: { | |
comments: false, | |
}, | |
}), | |
new HtmlWebpackPlugin({ template: __dirname + '/src/index.html' }), | |
new webpack.LoaderOptionsPlugin({ | |
minimize: true | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendor', | |
minChunks: Infinity, | |
filename: '[name].bundle.js' | |
}), | |
new webpack.EnvironmentPlugin({ | |
NODE_ENV: nodeEnv | |
}), | |
new webpack.NamedModulesPlugin(), | |
new webpack.HotModuleReplacementPlugin(), | |
], | |
devServer: { | |
hot: true, | |
contentBase: path.resolve(__dirname, 'dist'), | |
publicPath: '/' | |
} | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment