This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.prod.js
170 lines (127 loc) · 4 KB
/
webpack.config.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
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
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var awesomeTs = require('awesome-typescript-loader');
var common = require('./webpack.common.js');
// ensure production environment
process.env.NODE_ENV = 'production';
var config = {
// Source maps are completely regenerated for each chunk at each build
devtool: 'source-map',
// Set base directory for resolving entry points
context: common.absPaths.clientSrc,
// Client application only, no dev server
entry: {
'vendor': common.absPaths.vendorEntryAot,
'main': common.absPaths.mainEntryAot,
},
output: {
path: common.absPaths.buildOutput,
filename: common.relPaths.bundle,
sourceMapFilename: common.relPaths.sourceMap,
chunkFilename: common.relPaths.chunk,
publicPath: common.urls.public,
},
module: {
loaders: [
// Pre-loaders
common.rules.tslint,
// Loaders
common.rules.typescriptAot,
common.rules.componentSass,
common.rules.componentCss,
common.rules.globalCss,
common.rules.html,
// Post-loaders
// none
],
// speed up build by excluding some big libraries from parsing
noParse: common.noParse,
},
resolve: {
extensions: common.resolve.extensions,
modules: common.resolve.modules,
},
plugins: [
new webpack.DefinePlugin(common.buildDefines()),
// Until loaders are updated, use the LoaderOptionsPlugin to pass custom properties to third-party loaders
new webpack.LoaderOptionsPlugin({
// Put loaders into debug mode
// Note: this will be deprecated in v3 or later. Remove when loaders will update.
debug: false,
// Put loaders into minimize mode.
// Note: this will be deprecated in v3 or later. Remove when loaders will update.
minimize: true,
options: {
postcss: common.postcss,
},
}),
// Provides context to Angular's use of System.import
// See https://github.com/angular/angular/issues/11580
new webpack.ContextReplacementPlugin(
common.patterns.angularContext,
common.absPaths.clientSrc
),
new webpack.optimize.CommonsChunkPlugin({
name: ['main', 'vendor'],
filename: common.relPaths.bundle,
minChunks: mod => /node_modules/.test(mod.resource),
}),
// Minimize scripts
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
// to debug production build, uncomment lines in [debug] section and comment lines in [prod] section
// [prod]: Settings for production build
beautify: false,
mangle: {
screw_ie8 : true,
keep_fnames: true,
},
comments: false,
compress: {
warnings: false,
screw_ie8: true,
drop_debugger: true,
drop_console: true,
dead_code: true,
unused: true,
conditionals: true,
comparisons: true,
sequences: true,
evaluate: true,
if_return: true,
join_vars: true,
},
// [debug]: Settings when debugging production build
/*
beautify: true,
mangle: false,
comments: true,
compress: {
warnings: true,
screw_ie8: false,
drop_debugger: false,
drop_console: false,
dead_code: false,
unused: false,
conditionals: false,
comparisons: false,
sequences: false,
evaluate: false,
if_return: false,
join_vars: false,
},
*/
}),
// Only emit files when there are no errors
new webpack.NoEmitOnErrorsPlugin(),
// Copy static assets from their folder to common output folder
new CopyWebpackPlugin([{
from: common.absPaths.staticFiles,
}]),
// `CheckerPlugin` is optional. Use it if you want async error reporting.
// We need this plugin to detect a `--watch` mode. It may be removed later
// after https://github.com/webpack/webpack/issues/3460 will be resolved.
new awesomeTs.CheckerPlugin(),
],
};
module.exports = config;