-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
127 lines (119 loc) · 3.48 KB
/
webpack.prod.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
121
122
123
124
125
126
127
const webpack = require("webpack")
const path = require("path")
// Plugins
const UglifyJSPlugin = require("uglifyjs-webpack-plugin")
var CompressionPlugin = require("compression-webpack-plugin")
var SizeAnalyzerPlugin = require("webpack-bundle-size-analyzer")
.WebpackBundleSizeAnalyzerPlugin
var BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin
var HtmlWebpackPlugin = require("html-webpack-plugin")
// Experimental Plugins
const PrepackWebpackPlugin = require("prepack-webpack-plugin").default
const ShakePlugin = require("webpack-common-shake").Plugin
const DynamicCdnWebpackPlugin = require("dynamic-cdn-webpack-plugin")
module.exports = {
entry: ["./src/index.tsx"],
output: {
filename: "[name].[chunkhash].js",
path: path.resolve(__dirname + "/dist"),
},
devtool: "cheap-module-source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"],
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
exclude: path.resolve(__dirname, "node_modules"),
include: path.resolve(__dirname, "src"),
loader: [
"babel-loader",
{
loader: "awesome-typescript-loader",
options: { useBabel: true, useCache: true, sourceMap: true },
},
],
},
{
test: /\.ts$/,
enforce: "pre",
loader: "tslint-loader",
options: {
/* Loader options go here */
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: "src/index.html",
minify: {
removeComments: true,
collapseWhitespace: true,
},
}),
// The hashed module ID plugin is recommend over the named module
// plugin for production since it takes less time to run and does not
// depend on the path to the modules. This helps with caching chunks
// across builds by keeping chunks names the same when they don't change.
new webpack.HashedModuleIdsPlugin(),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production"),
}),
// The CDN plugin kind of works as a vendor bundle for react and react-dom
// by fetching them from a CDN on page load instead of in the main bundle.
new DynamicCdnWebpackPlugin({
env: "production",
only: ["react", "react-dom"],
}),
new UglifyJSPlugin({
uglifyOptions: {
compress: {
screw_ie8: true,
dead_code: true,
drop_debugger: true,
evaluate: true,
conditionals: true,
booleans: true,
if_return: true,
inline: true,
join_vars: true,
unused: true,
drop_console: true,
unsafe: true,
unsafe_comps: true,
},
},
mangle: {
screw_ie8: true,
},
// Check? Do sourcemaps work with parallel enabled?
parallel: {
cache: true,
workers: 2,
},
ie8: false,
cache: true,
workers: 2,
beautify: false,
comments: false,
sourceMap: true,
}),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 0,
minRatio: 0,
}),
new SizeAnalyzerPlugin("size_report.txt"),
new BundleAnalyzerPlugin({
analyzerMode: "static",
reportFilename: "size_report_visual.html",
defaultSizes: "gzip",
}),
],
}