1
|
const webpack = require('webpack');
|
2
|
const path = require('path');
|
3
|
const clone = require('js.clone');
|
4
|
const webpackMerge = require('webpack-merge');
|
5
|
const V8LazyParseWebpackPlugin = require('v8-lazy-parse-webpack-plugin');
|
6
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
7
|
import webpackConfig, { root, includeClientPackages } from './webpack.config';
|
8
|
// const CompressionPlugin = require('compression-webpack-plugin');
|
9
|
|
10
|
|
11
|
export const commonPlugins = [
|
12
|
new V8LazyParseWebpackPlugin(),
|
13
|
|
14
|
new webpack.DefinePlugin({
|
15
|
// do not use an object for 'process.env' otherwise all other environment
|
16
|
// variables are set to 'undefined' see issue #291
|
17
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
18
|
'process.env.AOT': true
|
19
|
}),
|
20
|
|
21
|
// Loader options
|
22
|
new webpack.LoaderOptionsPlugin({
|
23
|
minimize: true,
|
24
|
debug: false
|
25
|
}),
|
26
|
|
27
|
new webpack.NormalModuleReplacementPlugin(
|
28
|
/facade(\\|\/)async/,
|
29
|
root('node_modules/@angular/core/src/facade/async.js')
|
30
|
),
|
31
|
new webpack.NormalModuleReplacementPlugin(
|
32
|
/facade(\\|\/)collection/,
|
33
|
root('node_modules/@angular/core/src/facade/collection.js')
|
34
|
),
|
35
|
new webpack.NormalModuleReplacementPlugin(
|
36
|
/facade(\\|\/)errors/,
|
37
|
root('node_modules/@angular/core/src/facade/errors.js')
|
38
|
),
|
39
|
new webpack.NormalModuleReplacementPlugin(
|
40
|
/facade(\\|\/)lang/,
|
41
|
root('node_modules/@angular/core/src/facade/lang.js')
|
42
|
),
|
43
|
new webpack.NormalModuleReplacementPlugin(
|
44
|
/facade(\\|\/)math/,
|
45
|
root('node_modules/@angular/core/src/facade/math.js')
|
46
|
),
|
47
|
|
48
|
];
|
49
|
export const commonConfig = {
|
50
|
output: {
|
51
|
filename: '[name].bundle.js',
|
52
|
chunkFilename: '[chunkhash].js'
|
53
|
},
|
54
|
};
|
55
|
|
56
|
// Client.
|
57
|
export const clientPlugins = [
|
58
|
new BundleAnalyzerPlugin({
|
59
|
analyzerMode: 'disabled', // change it to `server` to view bundle stats
|
60
|
reportFilename: 'report.html',
|
61
|
generateStatsFile: true,
|
62
|
statsFilename: 'stats.json',
|
63
|
}),
|
64
|
// To use gzip, you can run 'npm install compression-webpack-plugin --save-dev'
|
65
|
// add 'var CompressionPlugin = require("compression-webpack-plugin");' on the top
|
66
|
// and comment out below codes
|
67
|
//
|
68
|
// new CompressionPlugin({
|
69
|
// asset: "[path].gz[query]",
|
70
|
// algorithm: "gzip",
|
71
|
// test: /\.js$|\.css$|\.html$/,
|
72
|
// threshold: 10240,
|
73
|
// minRatio: 0.8
|
74
|
// }),
|
75
|
|
76
|
new webpack.optimize.UglifyJsPlugin({
|
77
|
// beautify: true,
|
78
|
// mangle: false,
|
79
|
output: {
|
80
|
comments: false
|
81
|
},
|
82
|
compress: {
|
83
|
warnings: false,
|
84
|
conditionals: true,
|
85
|
unused: true,
|
86
|
comparisons: true,
|
87
|
sequences: true,
|
88
|
dead_code: true,
|
89
|
evaluate: true,
|
90
|
if_return: true,
|
91
|
join_vars: true,
|
92
|
negate_iife: false // we need this for lazy v8
|
93
|
},
|
94
|
sourceMap: true
|
95
|
}),
|
96
|
|
97
|
new webpack.NormalModuleReplacementPlugin(
|
98
|
/@angular(\\|\/)upgrade/,
|
99
|
root('empty.js')
|
100
|
),
|
101
|
// problem with platformUniversalDynamic on the server/client
|
102
|
new webpack.NormalModuleReplacementPlugin(
|
103
|
/@angular(\\|\/)compiler/,
|
104
|
root('empty.js')
|
105
|
),
|
106
|
new webpack.NormalModuleReplacementPlugin(
|
107
|
/@angular(\\|\/)platform-browser-dynamic/,
|
108
|
root('empty.js')
|
109
|
),
|
110
|
new webpack.NormalModuleReplacementPlugin(
|
111
|
/dom(\\|\/)debug(\\|\/)ng_probe/,
|
112
|
root('empty.js')
|
113
|
),
|
114
|
new webpack.NormalModuleReplacementPlugin(
|
115
|
/dom(\\|\/)debug(\\|\/)by/,
|
116
|
root('empty.js')
|
117
|
),
|
118
|
new webpack.NormalModuleReplacementPlugin(
|
119
|
/src(\\|\/)debug(\\|\/)debug_node/,
|
120
|
root('empty.js')
|
121
|
),
|
122
|
new webpack.NormalModuleReplacementPlugin(
|
123
|
/src(\\|\/)debug(\\|\/)debug_renderer/,
|
124
|
root('empty.js')
|
125
|
),
|
126
|
|
127
|
// Waiting for https://github.com/ampedandwired/html-webpack-plugin/issues/446
|
128
|
// new webpack.optimize.AggressiveSplittingPlugin({
|
129
|
// minSize: 30000,
|
130
|
// maxSize: 250000
|
131
|
// }),
|
132
|
|
133
|
];
|
134
|
export const clientConfig = {
|
135
|
entry: './src/client.aot',
|
136
|
recordsOutputPath: root('webpack.records.json')
|
137
|
};
|
138
|
|
139
|
// Server.
|
140
|
|
141
|
export const serverPlugins = [
|
142
|
new webpack.optimize.UglifyJsPlugin({
|
143
|
// beautify: true,
|
144
|
mangle: false, // to ensure process.env still works
|
145
|
output: {
|
146
|
comments: false
|
147
|
},
|
148
|
compress: {
|
149
|
warnings: false,
|
150
|
conditionals: true,
|
151
|
unused: true,
|
152
|
comparisons: true,
|
153
|
sequences: true,
|
154
|
dead_code: true,
|
155
|
evaluate: true,
|
156
|
if_return: true,
|
157
|
join_vars: true,
|
158
|
negate_iife: false // we need this for lazy v8
|
159
|
},
|
160
|
sourceMap: true
|
161
|
}),
|
162
|
];
|
163
|
export const serverConfig = {
|
164
|
entry: './src/server.aot',
|
165
|
output: {
|
166
|
filename: 'index.js',
|
167
|
chunkFilename: '[id].bundle.js',
|
168
|
crossOriginLoading: false
|
169
|
},
|
170
|
};
|
171
|
|
172
|
export default [
|
173
|
// Client
|
174
|
webpackMerge(webpackConfig[0], clone(commonConfig), clientConfig, {plugins: webpackConfig[0].plugins.concat(commonPlugins, clientPlugins) }),
|
175
|
|
176
|
// Server
|
177
|
webpackMerge(webpackConfig[1], clone(commonConfig), serverConfig, {plugins: webpackConfig[1].plugins.concat(commonPlugins, serverPlugins) })
|
178
|
];
|