-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
111 lines (103 loc) · 2.46 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const webpack = require('webpack');
// Webpack parts
const parts = require('./webpack.parts');
const PATHS = {
app: path.join(__dirname, 'src'),
build: path.join(__dirname, 'build'),
appHTML: `${path.join(__dirname, 'public')}/index.html`,
};
const commonConfig = merge([
{
entry: PATHS.app,
output: {
path: PATHS.build,
filename: '[name].js',
},
plugins: [
new HtmlWebpackPlugin({
template: PATHS.appHTML,
inject: true,
}),
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
},
// Turn off performance hints during development because we don't do any
// splitting or minification in interest of speed. These warnings become
// cumbersome.
performance: {
hints: false,
},
},
parts.loadJavascript(),
parts.lintJavascript(),
parts.loadFonts({
options: {
name: '[name].[hash:8].[ext]',
},
}),
]);
const developmentConfig = merge([
parts.devServer(),
parts.generateSourceMaps({ type: 'cheap-module-source-map' }),
parts.loadCSS(),
]);
const productionConfig = merge([
{
output: {
chunkFilename: '[name].[chunkhash:8].js',
filename: '[name].[chunkhash:8].js',
},
recordsPath: path.join(__dirname, 'records.json'),
plugins: [
new webpack.HashedModuleIdsPlugin(),
],
},
parts.extractBundles([
{
name: 'vendor',
minChunks: ({ resource }) => (
resource &&
resource.indexOf('node_modules') >= 0 &&
resource.match(/\.js$/)
),
},
{
name: 'manifest',
minChunks: Infinity,
},
]),
parts.minifyJavaScript(),
parts.minifyCSS({
options: {
discardComments: {
removeAll: true,
},
// Run cssnano in safe mode to avoid
// potentially unsafe transformations.
safe: true,
},
}),
parts.extractSCSS(),
parts.loadImages(),
parts.attachRevision(),
parts.clean(),
parts.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
]);
module.exports = (env) => {
if (env === 'production') {
return merge(commonConfig, productionConfig);
}
return merge(commonConfig, developmentConfig);
};