-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
80 lines (71 loc) · 1.77 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { resolve } = require('path')
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const isProd = process.env.NODE_ENV === 'production'
const prodUrl = ''
module.exports = {
entry: isProd
? [
'babel-polyfill',
'react',
'react-dom',
'./app/main.js',
]
: [
'babel-polyfill',
'react-hot-loader/patch',
'./app/main.js',
],
output: {
filename: isProd ? 'js/[name].[hash].js' : 'js/bundle.js',
path: resolve(__dirname, 'dist'),
publicPath: isProd ? prodUrl : '/',
},
devServer: {
historyApiFallback: true,
contentBase: resolve(__dirname, 'dist'),
publicPath: isProd ? prodUrl : '/',
},
node: {
console: true,
fs: 'empty',
net: 'empty',
tls: 'empty',
},
devtool: isProd ? 'cheap-module-source-map' : 'cheap-module-eval-source-map',
module: {
rules: [
{
test: /\.js$/,
include: [ resolve(__dirname, 'app') ],
loader: 'babel-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: {
alias: { 'app': resolve(__dirname, 'app') },
extensions: ['.js'],
},
plugins: [
new HtmlWebpackPlugin({
filename: resolve(__dirname, 'dist/index.html'),
template: resolve(__dirname, 'app/index.html'),
}),
...(isProd
? [
new BundleAnalyzerPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new UglifyJsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
]
: []),
],
}