-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (99 loc) · 2.44 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
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const uglifyJS = require('./webpack/plugins/uglify');
const concat = require('./webpack/plugins/concat');
const mergeChunks = require('./webpack/plugins/mergeChunks');
const hmr = require('./webpack/plugins/hmr');
const devServer = require('./webpack/devServer');
const visualizer = require('./webpack/plugins/visualizer');
const compileTime = require('./webpack/plugins/compile-time');
const autoDllPlugin = require('./webpack/plugins/autodll');
const commonChunkPlugin = require('./webpack/plugins/commons-chunk');
const vendors = require('./webpack/vendors');
const isProd =
!!process.env.NODE_ENV && process.env.NODE_ENV.trim() === 'production';
const APP_DIR = path.resolve(__dirname, './app/client/src');
const BUILD_DIR = path.resolve(__dirname, './dist');
const common = merge([
{
devtool: isProd ? 'source-map' : 'cheap-eval-source-map',
entry: {
main: `${APP_DIR}/app.js`
},
output: {
path: BUILD_DIR,
filename: '[name].[hash].js'
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
]
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'images/'
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
chunks: ['vendor', 'main'],
chunksSortMode: 'manual',
minify: {
collapseWhitespace: true
},
hash: true,
template: './public/index.html',
favicon: './public/favicon.ico'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
}
]);
const useVendorSplitting = merge([
{
entry: {
vendor: vendors
}
}
]);
module.exports = () => {
if (isProd) {
return merge([
common,
useVendorSplitting,
commonChunkPlugin(),
concat(),
uglifyJS(),
mergeChunks()
]);
}
return merge([
common,
devServer(),
hmr(),
visualizer(),
compileTime(),
autoDllPlugin()
]);
};