-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.ts
88 lines (71 loc) · 2.21 KB
/
webpack.prod.ts
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
import * as webpack from 'webpack';
import path from 'path';
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
// The prod config is heavily based on the data in the dev config to keep things DRY.
const prodConfig = require('./webpack.dev').default;
prodConfig.mode = "production";
prodConfig.output.filename = "[name].[contenthash].bundle.js";
// It's actually NOT worth code splitting
/*
prodConfig.entry = {
results: './src/compiled/results.json',
main: {
import: './src/index.tsx',
dependOn: ['results'],
},
}
prodConfig.optimization = {
splitChunks: {
chunks: (chunk) => {
// I filter the chunks here so that things that aren't the main bundle are code split.
return chunk.name === 'main';
},
name: 'vendor'
},
runtimeChunk: 'single', // This needs to be single since I am injecting multiple entry points in to the page to do code splitting
}
*/
/*
prodConfig.optimization = {
splitChunks: {
chunks: (chunk) => {
// I filter the chunks here so that things that aren't the main bundle are code split.
return chunk.name === 'main';
},
name: 'vendor'
},
runtimeChunk: 'single', // This needs to be single since I am injecting multiple entry points in to the page to do code splitting
}
*/
prodConfig.plugins = prodConfig.plugins.filter((p: any) => {
if (p instanceof webpack.HotModuleReplacementPlugin) {
return false;
} else if (p instanceof webpack.DefinePlugin) {
return false;
}
return true;
});
prodConfig.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_DEBUG': JSON.stringify(false),
'process.env.DEVMODE': JSON.stringify(false),
'process.env.SERVICE_ENDPOINT': JSON.stringify('/'),
})
);
prodConfig.plugins.push(
new CopyWebpackPlugin({
patterns: [{
from: path.resolve(__dirname, "src", "assets"),
to: 'assets'
}]
})
);
/*
prodConfig.plugins.push(
new BundleAnalyzerPlugin()
);
*/
prodConfig.devtool = false;
prodConfig.stats = "errors-only";
export default prodConfig;