forked from angular/universal-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.ts
178 lines (163 loc) · 4.68 KB
/
webpack.prod.config.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
const webpack = require('webpack');
const path = require('path');
const clone = require('js.clone');
const webpackMerge = require('webpack-merge');
const V8LazyParseWebpackPlugin = require('v8-lazy-parse-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
import webpackConfig, { root, includeClientPackages } from './webpack.config';
// const CompressionPlugin = require('compression-webpack-plugin');
export const commonPlugins = [
new V8LazyParseWebpackPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
'AOT': true
}
}),
// Loader options
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.NormalModuleReplacementPlugin(
/facade(\\|\/)async/,
root('node_modules/@angular/core/src/facade/async.js')
),
new webpack.NormalModuleReplacementPlugin(
/facade(\\|\/)collection/,
root('node_modules/@angular/core/src/facade/collection.js')
),
new webpack.NormalModuleReplacementPlugin(
/facade(\\|\/)errors/,
root('node_modules/@angular/core/src/facade/errors.js')
),
new webpack.NormalModuleReplacementPlugin(
/facade(\\|\/)lang/,
root('node_modules/@angular/core/src/facade/lang.js')
),
new webpack.NormalModuleReplacementPlugin(
/facade(\\|\/)math/,
root('node_modules/@angular/core/src/facade/math.js')
),
];
export const commonConfig = {
output: {
filename: '[name].bundle.js',
chunkFilename: '[chunkhash].js'
},
};
// Client.
export const clientPlugins = [
new BundleAnalyzerPlugin({
analyzerMode: 'disabled', // change it to `server` to view bundle stats
reportFilename: 'report.html',
generateStatsFile: true,
statsFilename: 'stats.json',
}),
// To use gzip, you can run 'npm install compression-webpack-plugin --save-dev'
// add 'var CompressionPlugin = require("compression-webpack-plugin");' on the top
// and comment out below codes
//
// new CompressionPlugin({
// asset: "[path].gz[query]",
// algorithm: "gzip",
// test: /\.js$|\.css$|\.html$/,
// threshold: 10240,
// minRatio: 0.8
// }),
new webpack.optimize.UglifyJsPlugin({
// beautify: true,
// mangle: false,
output: {
comments: false
},
compress: {
warnings: false,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
negate_iife: false // we need this for lazy v8
},
sourceMap: true
}),
new webpack.NormalModuleReplacementPlugin(
/@angular(\\|\/)upgrade/,
root('empty.js')
),
// problem with platformUniversalDynamic on the server/client
new webpack.NormalModuleReplacementPlugin(
/@angular(\\|\/)compiler/,
root('empty.js')
),
new webpack.NormalModuleReplacementPlugin(
/@angular(\\|\/)platform-browser-dynamic/,
root('empty.js')
),
new webpack.NormalModuleReplacementPlugin(
/dom(\\|\/)debug(\\|\/)ng_probe/,
root('empty.js')
),
new webpack.NormalModuleReplacementPlugin(
/dom(\\|\/)debug(\\|\/)by/,
root('empty.js')
),
new webpack.NormalModuleReplacementPlugin(
/src(\\|\/)debug(\\|\/)debug_node/,
root('empty.js')
),
new webpack.NormalModuleReplacementPlugin(
/src(\\|\/)debug(\\|\/)debug_renderer/,
root('empty.js')
),
// Waiting for https://github.com/ampedandwired/html-webpack-plugin/issues/446
// new webpack.optimize.AggressiveSplittingPlugin({
// minSize: 30000,
// maxSize: 250000
// }),
];
export const clientConfig = {
entry: './src/client.aot',
recordsOutputPath: root('webpack.records.json')
};
// Server.
export const serverPlugins = [
new webpack.optimize.UglifyJsPlugin({
// beautify: true,
mangle: false, // to ensure process.env still works
output: {
comments: false
},
compress: {
warnings: false,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
negate_iife: false // we need this for lazy v8
},
sourceMap: true
}),
];
export const serverConfig = {
entry: './src/server.aot',
output: {
filename: 'index.js',
chunkFilename: '[id].bundle.js',
crossOriginLoading: false
},
};
export default [
// Client
webpackMerge(webpackConfig[0], clone(commonConfig), clientConfig, {plugins: webpackConfig[0].plugins.concat(commonPlugins, clientPlugins) }),
// Server
webpackMerge(webpackConfig[1], clone(commonConfig), serverConfig, {plugins: webpackConfig[1].plugins.concat(commonPlugins, serverPlugins) })
];