-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwebpack.config.js
120 lines (109 loc) · 3.32 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const basePlugins = [
new webpack.DefinePlugin({
__DEV__: process.env.NODE_ENV !== 'production',
__PRODUCTION__: process.env.NODE_ENV === 'production',
__BASE__: JSON.stringify(process.env.BASE),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html'
})
];
const baseEntry = [
'./src/index'
];
const baseBabelLoaders = [
'babel'
];
const devPlugins = [
new webpack.HotModuleReplacementPlugin()
];
const devEntries = [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server'
];
const devBabelLoaders = [
'react-hot-loader/webpack'
];
const prodPlugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false,
compress: {
sequences: true,
booleans: true,
loops: true,
unused: true,
warnings: false,
drop_console: true
}
}),
new FaviconsWebpackPlugin('./static/img/favicon.png')
];
const babelLoaders = baseBabelLoaders
.concat(process.env.NODE_ENV === 'development' ? devBabelLoaders : []);
const plugins = basePlugins
.concat(process.env.NODE_ENV === 'production' ? prodPlugins : [])
.concat(process.env.NODE_ENV === 'development' ? devPlugins : []);
const entries = baseEntry
.concat(process.env.NODE_ENV === 'development' ? devEntries : []);
module.exports = {
entry: entries,
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js'
},
plugins: plugins,
module: {
rules: [{
test: /\.js$/,
use: ['react-hot-loader/webpack', 'babel-loader'],
exclude: '/node_modules/',
include: [
path.join(__dirname, 'node_modules/ethereum-address'),
path.join(__dirname, 'src')
]
}, {
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
exclude: '/node_modules/',
include: path.join(__dirname, 'src')
}, {
test: /\.json$/,
use: 'json-loader',
exclude: '/node_modules/',
include: path.join(__dirname, 'src')
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'file-loader?name=img/[name].[ext]',
'image-webpack-loader'
],
exclude: '/node_modules/',
include: path.join(__dirname, 'static/img')
}, {
test: /\.(ttf)$/i,
use: 'file-loader?name=font/[name].[ext]',
exclude: '/node_modules/',
include: path.join(__dirname, 'static/font')
}]
}
};