aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/config/webpack.prod.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/config/webpack.prod.js')
-rw-r--r--client/config/webpack.prod.js455
1 files changed, 230 insertions, 225 deletions
diff --git a/client/config/webpack.prod.js b/client/config/webpack.prod.js
index 4f33961f5..ddc9343a7 100644
--- a/client/config/webpack.prod.js
+++ b/client/config/webpack.prod.js
@@ -5,6 +5,7 @@
5const helpers = require('./helpers') 5const helpers = require('./helpers')
6const webpackMerge = require('webpack-merge') // used to merge webpack configs 6const webpackMerge = require('webpack-merge') // used to merge webpack configs
7const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev 7const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
8const videoEmbedConfig = require('./webpack.video-embed.js')
8 9
9/** 10/**
10 * Webpack Plugins 11 * Webpack Plugins
@@ -31,266 +32,270 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
31}) 32})
32 33
33module.exports = function (env) { 34module.exports = function (env) {
34 return webpackMerge(commonConfig({env: ENV}), { 35 return [
35 /** 36 videoEmbedConfig({ env: ENV }),
36 * Developer tool to enhance debugging
37 *
38 * See: http://webpack.github.io/docs/configuration.html#devtool
39 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
40 */
41 devtool: 'source-map',
42
43 /**
44 * Options affecting the output of the compilation.
45 *
46 * See: http://webpack.github.io/docs/configuration.html#output
47 */
48 output: {
49 37
38 webpackMerge(commonConfig({ env: ENV }), {
50 /** 39 /**
51 * The output directory as absolute path (required). 40 * Developer tool to enhance debugging
52 * 41 *
53 * See: http://webpack.github.io/docs/configuration.html#output-path 42 * See: http://webpack.github.io/docs/configuration.html#devtool
43 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
54 */ 44 */
55 path: helpers.root('dist'), 45 devtool: 'source-map',
56 46
57 /** 47 /**
58 * Specifies the name of each output file on disk. 48 * Options affecting the output of the compilation.
59 * IMPORTANT: You must not specify an absolute path here!
60 * 49 *
61 * See: http://webpack.github.io/docs/configuration.html#output-filename 50 * See: http://webpack.github.io/docs/configuration.html#output
62 */ 51 */
63 filename: '[name].[chunkhash].bundle.js', 52 output: {
64 53
65 /** 54 /**
66 * The filename of the SourceMaps for the JavaScript files. 55 * The output directory as absolute path (required).
67 * They are inside the output.path directory. 56 *
68 * 57 * See: http://webpack.github.io/docs/configuration.html#output-path
69 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename 58 */
70 */ 59 path: helpers.root('dist'),
71 sourceMapFilename: '[file].map',
72 60
73 /** 61 /**
74 * The filename of non-entry chunks as relative path 62 * Specifies the name of each output file on disk.
75 * inside the output.path directory. 63 * IMPORTANT: You must not specify an absolute path here!
76 * 64 *
77 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename 65 * See: http://webpack.github.io/docs/configuration.html#output-filename
78 */ 66 */
79 chunkFilename: '[name].[chunkhash].chunk.js', 67 filename: '[name].[chunkhash].bundle.js',
68
69 /**
70 * The filename of the SourceMaps for the JavaScript files.
71 * They are inside the output.path directory.
72 *
73 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
74 */
75 sourceMapFilename: '[file].map',
80 76
81 publicPath: '/client/' 77 /**
82 }, 78 * The filename of non-entry chunks as relative path
79 * inside the output.path directory.
80 *
81 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
82 */
83 chunkFilename: '[name].[chunkhash].chunk.js',
83 84
84 module: { 85 publicPath: '/client/'
85 rules: [ 86 },
86 { 87
87 test: /junk\/index\.js$/, 88 module: {
88 // exclude: /(node_modules|bower_components)/, 89 rules: [
89 use: { 90 {
90 loader: 'babel-loader', 91 test: /junk\/index\.js$/,
91 options: { 92 // exclude: /(node_modules|bower_components)/,
92 presets: [ 'env' ] 93 use: {
94 loader: 'babel-loader',
95 options: {
96 presets: [ 'env' ]
97 }
93 } 98 }
94 } 99 }
95 } 100 ]
96 ] 101 },
97 },
98
99 /**
100 * Add additional plugins to the compiler.
101 *
102 * See: http://webpack.github.io/docs/configuration.html#plugins
103 */
104 plugins: [
105 102
106 /** 103 /**
107 * Webpack plugin to optimize a JavaScript file for faster initial load 104 * Add additional plugins to the compiler.
108 * by wrapping eagerly-invoked functions.
109 * 105 *
110 * See: https://github.com/vigneshshanmugam/optimize-js-plugin 106 * See: http://webpack.github.io/docs/configuration.html#plugins
111 */ 107 */
108 plugins: [
112 109
113 new OptimizeJsPlugin({ 110 /**
114 sourceMap: false 111 * Webpack plugin to optimize a JavaScript file for faster initial load
115 }), 112 * by wrapping eagerly-invoked functions.
113 *
114 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
115 */
116 116
117 /** 117 new OptimizeJsPlugin({
118 * Plugin: DedupePlugin 118 sourceMap: false
119 * Description: Prevents the inclusion of duplicate code into your bundle 119 }),
120 * and instead applies a copy of the function at runtime.
121 *
122 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
123 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
124 */
125 // new DedupePlugin(),
126 120
127 /** 121 /**
128 * Plugin: DefinePlugin 122 * Plugin: DedupePlugin
129 * Description: Define free variables. 123 * Description: Prevents the inclusion of duplicate code into your bundle
130 * Useful for having development builds with debug logging or adding global constants. 124 * and instead applies a copy of the function at runtime.
131 * 125 *
132 * Environment helpers 126 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
133 * 127 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
134 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin 128 */
135 */ 129 // new DedupePlugin(),
136 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts 130
137 new DefinePlugin({ 131 /**
138 'ENV': JSON.stringify(METADATA.ENV), 132 * Plugin: DefinePlugin
139 'HMR': METADATA.HMR, 133 * Description: Define free variables.
140 'API_URL': JSON.stringify(METADATA.API_URL), 134 * Useful for having development builds with debug logging or adding global constants.
141 'process.version': JSON.stringify(process.version), 135 *
142 'process.env': { 136 * Environment helpers
137 *
138 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
139 */
140 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
141 new DefinePlugin({
143 'ENV': JSON.stringify(METADATA.ENV), 142 'ENV': JSON.stringify(METADATA.ENV),
144 'NODE_ENV': JSON.stringify(METADATA.ENV), 143 'HMR': METADATA.HMR,
145 'HMR': METADATA.HMR 144 'API_URL': JSON.stringify(METADATA.API_URL),
146 } 145 'process.version': JSON.stringify(process.version),
147 }), 146 'process.env': {
147 'ENV': JSON.stringify(METADATA.ENV),
148 'NODE_ENV': JSON.stringify(METADATA.ENV),
149 'HMR': METADATA.HMR
150 }
151 }),
148 152
149 /** 153 /**
150 * Plugin: UglifyJsPlugin 154 * Plugin: UglifyJsPlugin
151 * Description: Minimize all JavaScript output of chunks. 155 * Description: Minimize all JavaScript output of chunks.
152 * Loaders are switched into minimizing mode. 156 * Loaders are switched into minimizing mode.
153 * 157 *
154 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin 158 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
155 */ 159 */
156 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines 160 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
157 new UglifyJsPlugin({ 161 new UglifyJsPlugin({
158 // beautify: true, //debug 162 // beautify: true, //debug
159 // mangle: false, //debug 163 // mangle: false, //debug
160 // dead_code: false, //debug 164 // dead_code: false, //debug
161 // unused: false, //debug 165 // unused: false, //debug
162 // deadCode: false, //debug 166 // deadCode: false, //debug
163 // compress: { 167 // compress: {
164 // screw_ie8: true, 168 // screw_ie8: true,
165 // keep_fnames: true, 169 // keep_fnames: true,
166 // drop_debugger: false, 170 // drop_debugger: false,
167 // dead_code: false, 171 // dead_code: false,
168 // unused: false 172 // unused: false
169 // }, // debug 173 // }, // debug
170 // comments: true, //debug 174 // comments: true, //debug
171 175
172 beautify: false, // prod 176 beautify: false, // prod
173 output: { 177 output: {
174 comments: false 178 comments: false
175 }, // prod 179 }, // prod
176 mangle: { 180 mangle: {
177 screw_ie8: true 181 screw_ie8: true
178 }, // prod 182 }, // prod
179 compress: { 183 compress: {
180 screw_ie8: true, 184 screw_ie8: true,
181 warnings: false, 185 warnings: false,
182 conditionals: true, 186 conditionals: true,
183 unused: true, 187 unused: true,
184 comparisons: true, 188 comparisons: true,
185 sequences: true, 189 sequences: true,
186 dead_code: true, 190 dead_code: true,
187 evaluate: true, 191 evaluate: true,
188 if_return: true, 192 if_return: true,
189 join_vars: true, 193 join_vars: true,
190 negate_iife: false // we need this for lazy v8 194 negate_iife: false // we need this for lazy v8
191 } 195 }
192 }), 196 }),
193 197
194 new NormalModuleReplacementPlugin( 198 new NormalModuleReplacementPlugin(
195 /angular2-hmr/, 199 /angular2-hmr/,
196 helpers.root('config/empty.js') 200 helpers.root('config/empty.js')
197 ), 201 ),
198 202
199 new NormalModuleReplacementPlugin( 203 new NormalModuleReplacementPlugin(
200 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/, 204 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
201 helpers.root('config/empty.js') 205 helpers.root('config/empty.js')
202 ), 206 ),
203 207
204 new HashedModuleIdsPlugin(), 208 new HashedModuleIdsPlugin(),
205 209
206 /** 210 /**
207 * Plugin: IgnorePlugin 211 * Plugin: IgnorePlugin
208 * Description: Don’t generate modules for requests matching the provided RegExp. 212 * Description: Don’t generate modules for requests matching the provided RegExp.
209 * 213 *
210 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin 214 * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
211 */ 215 */
212 216
213 // new IgnorePlugin(/angular2-hmr/), 217 // new IgnorePlugin(/angular2-hmr/),
214 218
215 /** 219 /**
216 * Plugin: CompressionPlugin 220 * Plugin: CompressionPlugin
217 * Description: Prepares compressed versions of assets to serve 221 * Description: Prepares compressed versions of assets to serve
218 * them with Content-Encoding 222 * them with Content-Encoding
219 * 223 *
220 * See: https://github.com/webpack/compression-webpack-plugin 224 * See: https://github.com/webpack/compression-webpack-plugin
221 */ 225 */
222 // install compression-webpack-plugin 226 // install compression-webpack-plugin
223 // new CompressionPlugin({ 227 // new CompressionPlugin({
224 // regExp: /\.css$|\.html$|\.js$|\.map$/, 228 // regExp: /\.css$|\.html$|\.js$|\.map$/,
225 // threshold: 2 * 1024 229 // threshold: 2 * 1024
226 // }) 230 // })
227 231
228 /** 232 /**
229 * Plugin LoaderOptionsPlugin (experimental) 233 * Plugin LoaderOptionsPlugin (experimental)
230 * 234 *
231 * See: https://gist.github.com/sokra/27b24881210b56bbaff7 235 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
232 */ 236 */
233 new LoaderOptionsPlugin({ 237 new LoaderOptionsPlugin({
234 minimize: true, 238 minimize: true,
235 debug: false, 239 debug: false,
236 options: { 240 options: {
237 241
238 /** 242 /**
239 * Static analysis linter for TypeScript advanced options configuration 243 * Static analysis linter for TypeScript advanced options configuration
240 * Description: An extensible linter for the TypeScript language. 244 * Description: An extensible linter for the TypeScript language.
241 * 245 *
242 * See: https://github.com/wbuchwalter/tslint-loader 246 * See: https://github.com/wbuchwalter/tslint-loader
243 */ 247 */
244 tslint: { 248 tslint: {
245 emitErrors: true, 249 emitErrors: true,
246 failOnHint: true, 250 failOnHint: true,
247 resourcePath: 'src' 251 resourcePath: 'src'
248 }, 252 },
249 253
250 /** 254 /**
251 * Html loader advanced options 255 * Html loader advanced options
252 * 256 *
253 * See: https://github.com/webpack/html-loader#advanced-options 257 * See: https://github.com/webpack/html-loader#advanced-options
254 */ 258 */
255 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor 259 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
256 htmlLoader: { 260 htmlLoader: {
257 minimize: true, 261 minimize: true,
258 removeAttributeQuotes: false, 262 removeAttributeQuotes: false,
259 caseSensitive: true, 263 caseSensitive: true,
260 customAttrSurround: [ 264 customAttrSurround: [
261 [/#/, /(?:)/], 265 [/#/, /(?:)/],
262 [/\*/, /(?:)/], 266 [/\*/, /(?:)/],
263 [/\[?\(?/, /(?:)/] 267 [/\[?\(?/, /(?:)/]
264 ], 268 ],
265 customAttrAssign: [/\)?]?=/] 269 customAttrAssign: [/\)?]?=/]
266 }, 270 },
267 271
268 // FIXME: Remove 272 // FIXME: Remove
269 // https://github.com/bholloway/resolve-url-loader/issues/36 273 // https://github.com/bholloway/resolve-url-loader/issues/36
270 // https://github.com/jtangelder/sass-loader/issues/289 274 // https://github.com/jtangelder/sass-loader/issues/289
271 context: __dirname, 275 context: __dirname,
272 output: { 276 output: {
273 path: helpers.root('dist') 277 path: helpers.root('dist')
278 }
274 } 279 }
275 } 280 })
276 }) 281 ],
277 ],
278 282
279 /* 283 /*
280 * Include polyfills or mocks for various node stuff 284 * Include polyfills or mocks for various node stuff
281 * Description: Node configuration 285 * Description: Node configuration
282 * 286 *
283 * See: https://webpack.github.io/docs/configuration.html#node 287 * See: https://webpack.github.io/docs/configuration.html#node
284 */ 288 */
285 node: { 289 node: {
286 global: true, 290 global: true,
287 crypto: 'empty', 291 crypto: 'empty',
288 fs: 'empty', 292 fs: 'empty',
289 process: true, 293 process: true,
290 module: false, 294 module: false,
291 clearImmediate: false, 295 clearImmediate: false,
292 setImmediate: false 296 setImmediate: false
293 } 297 }
294 298
295 }) 299 })
300 ]
296} 301}