diff options
Diffstat (limited to 'client/config/webpack.prod.js')
-rw-r--r-- | client/config/webpack.prod.js | 357 |
1 files changed, 179 insertions, 178 deletions
diff --git a/client/config/webpack.prod.js b/client/config/webpack.prod.js index 7ce5727d3..46db54482 100644 --- a/client/config/webpack.prod.js +++ b/client/config/webpack.prod.js | |||
@@ -9,10 +9,12 @@ const commonConfig = require('./webpack.common.js') // the settings that are com | |||
9 | /** | 9 | /** |
10 | * Webpack Plugins | 10 | * Webpack Plugins |
11 | */ | 11 | */ |
12 | // const ProvidePlugin = require('webpack/lib/ProvidePlugin') | ||
12 | const DefinePlugin = require('webpack/lib/DefinePlugin') | 13 | const DefinePlugin = require('webpack/lib/DefinePlugin') |
13 | const DedupePlugin = require('webpack/lib/optimize/DedupePlugin') | 14 | const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') |
15 | // const IgnorePlugin = require('webpack/lib/IgnorePlugin') | ||
16 | // const DedupePlugin = require('webpack/lib/optimize/DedupePlugin') | ||
14 | const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') | 17 | const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') |
15 | const CompressionPlugin = require('compression-webpack-plugin') | ||
16 | const WebpackMd5Hash = require('webpack-md5-hash') | 18 | const WebpackMd5Hash = require('webpack-md5-hash') |
17 | 19 | ||
18 | /** | 20 | /** |
@@ -21,211 +23,210 @@ const WebpackMd5Hash = require('webpack-md5-hash') | |||
21 | const ENV = process.env.NODE_ENV = process.env.ENV = 'production' | 23 | const ENV = process.env.NODE_ENV = process.env.ENV = 'production' |
22 | const HOST = process.env.HOST || 'localhost' | 24 | const HOST = process.env.HOST || 'localhost' |
23 | const PORT = process.env.PORT || 8080 | 25 | const PORT = process.env.PORT || 8080 |
24 | const METADATA = webpackMerge(commonConfig.metadata, { | 26 | const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, { |
25 | host: HOST, | 27 | host: HOST, |
26 | port: PORT, | 28 | port: PORT, |
27 | ENV: ENV, | 29 | ENV: ENV, |
28 | HMR: false | 30 | HMR: false |
29 | }) | 31 | }) |
30 | 32 | ||
31 | module.exports = webpackMerge(commonConfig, { | 33 | module.exports = function (env) { |
32 | /** | 34 | return webpackMerge(commonConfig({env: ENV}), { |
33 | * Switch loaders to debug mode. | ||
34 | * | ||
35 | * See: http://webpack.github.io/docs/configuration.html#debug | ||
36 | */ | ||
37 | debug: false, | ||
38 | |||
39 | /** | ||
40 | * Developer tool to enhance debugging | ||
41 | * | ||
42 | * See: http://webpack.github.io/docs/configuration.html#devtool | ||
43 | * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps | ||
44 | */ | ||
45 | devtool: 'source-map', | ||
46 | |||
47 | /** | ||
48 | * Options affecting the output of the compilation. | ||
49 | * | ||
50 | * See: http://webpack.github.io/docs/configuration.html#output | ||
51 | */ | ||
52 | output: { | ||
53 | /** | 35 | /** |
54 | * The output directory as absolute path (required). | 36 | * Switch loaders to debug mode. |
55 | * | 37 | * |
56 | * See: http://webpack.github.io/docs/configuration.html#output-path | 38 | * See: http://webpack.github.io/docs/configuration.html#debug |
57 | */ | 39 | */ |
58 | path: helpers.root('dist'), | 40 | debug: false, |
59 | 41 | ||
60 | /** | 42 | /** |
61 | * Specifies the name of each output file on disk. | 43 | * Developer tool to enhance debugging |
62 | * IMPORTANT: You must not specify an absolute path here! | ||
63 | * | 44 | * |
64 | * See: http://webpack.github.io/docs/configuration.html#output-filename | 45 | * See: http://webpack.github.io/docs/configuration.html#devtool |
46 | * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps | ||
65 | */ | 47 | */ |
66 | filename: '[name].[chunkhash].bundle.js', | 48 | devtool: 'source-map', |
67 | 49 | ||
68 | /** | 50 | /** |
69 | * The filename of the SourceMaps for the JavaScript files. | 51 | * Options affecting the output of the compilation. |
70 | * They are inside the output.path directory. | ||
71 | * | 52 | * |
72 | * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename | 53 | * See: http://webpack.github.io/docs/configuration.html#output |
73 | */ | 54 | */ |
74 | sourceMapFilename: '[name].[chunkhash].bundle.map', | 55 | output: { |
56 | /** | ||
57 | * The output directory as absolute path (required). | ||
58 | * | ||
59 | * See: http://webpack.github.io/docs/configuration.html#output-path | ||
60 | */ | ||
61 | path: helpers.root('dist'), | ||
62 | |||
63 | /** | ||
64 | * Specifies the name of each output file on disk. | ||
65 | * IMPORTANT: You must not specify an absolute path here! | ||
66 | * | ||
67 | * See: http://webpack.github.io/docs/configuration.html#output-filename | ||
68 | */ | ||
69 | filename: '[name].[chunkhash].bundle.js', | ||
70 | |||
71 | /** | ||
72 | * The filename of the SourceMaps for the JavaScript files. | ||
73 | * They are inside the output.path directory. | ||
74 | * | ||
75 | * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename | ||
76 | */ | ||
77 | sourceMapFilename: '[name].[chunkhash].bundle.map', | ||
78 | |||
79 | /** | ||
80 | * The filename of non-entry chunks as relative path | ||
81 | * inside the output.path directory. | ||
82 | * | ||
83 | * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename | ||
84 | */ | ||
85 | chunkFilename: '[id].[chunkhash].chunk.js' | ||
86 | |||
87 | }, | ||
88 | |||
89 | externals: { | ||
90 | webtorrent: 'WebTorrent' | ||
91 | }, | ||
75 | 92 | ||
76 | /** | 93 | /** |
77 | * The filename of non-entry chunks as relative path | 94 | * Add additional plugins to the compiler. |
78 | * inside the output.path directory. | ||
79 | * | 95 | * |
80 | * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename | 96 | * See: http://webpack.github.io/docs/configuration.html#plugins |
81 | */ | 97 | */ |
82 | chunkFilename: '[id].[chunkhash].chunk.js' | 98 | plugins: [ |
83 | 99 | ||
84 | }, | 100 | /** |
85 | 101 | * Plugin: WebpackMd5Hash | |
86 | externals: { | 102 | * Description: Plugin to replace a standard webpack chunkhash with md5. |
87 | webtorrent: 'WebTorrent' | 103 | * |
88 | }, | 104 | * See: https://www.npmjs.com/package/webpack-md5-hash |
89 | 105 | */ | |
90 | /** | 106 | new WebpackMd5Hash(), |
91 | * Add additional plugins to the compiler. | 107 | |
92 | * | 108 | /** |
93 | * See: http://webpack.github.io/docs/configuration.html#plugins | 109 | * Plugin: DedupePlugin |
94 | */ | 110 | * Description: Prevents the inclusion of duplicate code into your bundle |
95 | plugins: [ | 111 | * and instead applies a copy of the function at runtime. |
96 | 112 | * | |
97 | /** | 113 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin |
98 | * Plugin: WebpackMd5Hash | 114 | * See: https://github.com/webpack/docs/wiki/optimization#deduplication |
99 | * Description: Plugin to replace a standard webpack chunkhash with md5. | 115 | */ |
100 | * | 116 | // new DedupePlugin(), |
101 | * See: https://www.npmjs.com/package/webpack-md5-hash | 117 | |
102 | */ | 118 | /** |
103 | new WebpackMd5Hash(), | 119 | * Plugin: DefinePlugin |
120 | * Description: Define free variables. | ||
121 | * Useful for having development builds with debug logging or adding global constants. | ||
122 | * | ||
123 | * Environment helpers | ||
124 | * | ||
125 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | ||
126 | */ | ||
127 | // NOTE: when adding more properties make sure you include them in custom-typings.d.ts | ||
128 | new DefinePlugin({ | ||
129 | 'ENV': JSON.stringify(METADATA.ENV), | ||
130 | 'HMR': METADATA.HMR, | ||
131 | 'process.env': { | ||
132 | 'ENV': JSON.stringify(METADATA.ENV), | ||
133 | 'NODE_ENV': JSON.stringify(METADATA.ENV), | ||
134 | 'HMR': METADATA.HMR | ||
135 | } | ||
136 | }), | ||
137 | |||
138 | /** | ||
139 | * Plugin: UglifyJsPlugin | ||
140 | * Description: Minimize all JavaScript output of chunks. | ||
141 | * Loaders are switched into minimizing mode. | ||
142 | * | ||
143 | * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin | ||
144 | */ | ||
145 | // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines | ||
146 | new UglifyJsPlugin({ | ||
147 | // beautify: true, //debug | ||
148 | // mangle: false, //debug | ||
149 | // dead_code: false, //debug | ||
150 | // unused: false, //debug | ||
151 | // deadCode: false, //debug | ||
152 | // compress: { | ||
153 | // screw_ie8: true, | ||
154 | // keep_fnames: true, | ||
155 | // drop_debugger: false, | ||
156 | // dead_code: false, | ||
157 | // unused: false | ||
158 | // }, // debug | ||
159 | // comments: true, //debug | ||
160 | |||
161 | beautify: false, // prod | ||
162 | mangle: { screw_ie8: true, keep_fnames: true }, // prod | ||
163 | compress: { screw_ie8: true }, // prod | ||
164 | comments: false // prod | ||
165 | }), | ||
166 | |||
167 | new NormalModuleReplacementPlugin( | ||
168 | /angular2-hmr/, | ||
169 | helpers.root('config/modules/angular2-hmr-prod.js') | ||
170 | ) | ||
171 | |||
172 | /** | ||
173 | * Plugin: CompressionPlugin | ||
174 | * Description: Prepares compressed versions of assets to serve | ||
175 | * them with Content-Encoding | ||
176 | * | ||
177 | * See: https://github.com/webpack/compression-webpack-plugin | ||
178 | */ | ||
179 | // new CompressionPlugin({ | ||
180 | // regExp: /\.css$|\.html$|\.js$|\.map$/, | ||
181 | // threshold: 2 * 1024 | ||
182 | // }) | ||
104 | 183 | ||
105 | /** | 184 | ], |
106 | * Plugin: DedupePlugin | ||
107 | * Description: Prevents the inclusion of duplicate code into your bundle | ||
108 | * and instead applies a copy of the function at runtime. | ||
109 | * | ||
110 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | ||
111 | * See: https://github.com/webpack/docs/wiki/optimization#deduplication | ||
112 | */ | ||
113 | new DedupePlugin(), | ||
114 | 185 | ||
115 | /** | 186 | /** |
116 | * Plugin: DefinePlugin | 187 | * Static analysis linter for TypeScript advanced options configuration |
117 | * Description: Define free variables. | 188 | * Description: An extensible linter for the TypeScript language. |
118 | * Useful for having development builds with debug logging or adding global constants. | ||
119 | * | ||
120 | * Environment helpers | ||
121 | * | 189 | * |
122 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | 190 | * See: https://github.com/wbuchwalter/tslint-loader |
123 | */ | 191 | */ |
124 | // NOTE: when adding more properties make sure you include them in custom-typings.d.ts | 192 | tslint: { |
125 | new DefinePlugin({ | 193 | emitErrors: true, |
126 | 'ENV': JSON.stringify(METADATA.ENV), | 194 | failOnHint: true, |
127 | 'HMR': METADATA.HMR, | 195 | resourcePath: 'src' |
128 | 'process.env': { | 196 | }, |
129 | 'ENV': JSON.stringify(METADATA.ENV), | ||
130 | 'NODE_ENV': JSON.stringify(METADATA.ENV), | ||
131 | 'HMR': METADATA.HMR | ||
132 | } | ||
133 | }), | ||
134 | 197 | ||
135 | /** | 198 | /** |
136 | * Plugin: UglifyJsPlugin | 199 | * Html loader advanced options |
137 | * Description: Minimize all JavaScript output of chunks. | ||
138 | * Loaders are switched into minimizing mode. | ||
139 | * | 200 | * |
140 | * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin | 201 | * See: https://github.com/webpack/html-loader#advanced-options |
141 | */ | 202 | */ |
142 | // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines | 203 | // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor |
143 | new UglifyJsPlugin({ | 204 | htmlLoader: { |
144 | // beautify: true, //debug | 205 | minimize: true, |
145 | // mangle: false, //debug | 206 | removeAttributeQuotes: false, |
146 | // dead_code: false, //debug | 207 | caseSensitive: true, |
147 | // unused: false, //debug | 208 | customAttrSurround: [ |
148 | // deadCode: false, //debug | 209 | [/#/, /(?:)/], |
149 | // compress: { | 210 | [/\*/, /(?:)/], |
150 | // screw_ie8: true, | 211 | [/\[?\(?/, /(?:)/] |
151 | // keep_fnames: true, | 212 | ], |
152 | // drop_debugger: false, | 213 | customAttrAssign: [/\)?\]?=/] |
153 | // dead_code: false, | 214 | }, |
154 | // unused: false | 215 | |
155 | // }, // debug | 216 | /* |
156 | // comments: true, //debug | 217 | * Include polyfills or mocks for various node stuff |
157 | 218 | * Description: Node configuration | |
158 | beautify: false, // prod | ||
159 | |||
160 | mangle: { | ||
161 | screw_ie8: true, | ||
162 | keep_fnames: true | ||
163 | }, // prod | ||
164 | |||
165 | compress: { | ||
166 | screw_ie8: true | ||
167 | }, // prod | ||
168 | |||
169 | comments: false // prod | ||
170 | }), | ||
171 | |||
172 | /** | ||
173 | * Plugin: CompressionPlugin | ||
174 | * Description: Prepares compressed versions of assets to serve | ||
175 | * them with Content-Encoding | ||
176 | * | 219 | * |
177 | * See: https://github.com/webpack/compression-webpack-plugin | 220 | * See: https://webpack.github.io/docs/configuration.html#node |
178 | */ | 221 | */ |
179 | new CompressionPlugin({ | 222 | node: { |
180 | regExp: /\.css$|\.html$|\.js$|\.map$/, | 223 | global: 'window', |
181 | threshold: 2 * 1024 | 224 | crypto: 'empty', |
182 | }) | 225 | process: false, |
183 | 226 | module: false, | |
184 | ], | 227 | clearImmediate: false, |
185 | 228 | setImmediate: false | |
186 | /** | 229 | } |
187 | * Static analysis linter for TypeScript advanced options configuration | 230 | |
188 | * Description: An extensible linter for the TypeScript language. | 231 | }) |
189 | * | 232 | } |
190 | * See: https://github.com/wbuchwalter/tslint-loader | ||
191 | */ | ||
192 | tslint: { | ||
193 | emitErrors: true, | ||
194 | failOnHint: true, | ||
195 | resourcePath: 'src' | ||
196 | }, | ||
197 | |||
198 | /** | ||
199 | * Html loader advanced options | ||
200 | * | ||
201 | * See: https://github.com/webpack/html-loader#advanced-options | ||
202 | */ | ||
203 | // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor | ||
204 | htmlLoader: { | ||
205 | minimize: true, | ||
206 | removeAttributeQuotes: false, | ||
207 | caseSensitive: true, | ||
208 | customAttrSurround: [ | ||
209 | [/#/, /(?:)/], | ||
210 | [/\*/, /(?:)/], | ||
211 | [/\[?\(?/, /(?:)/] | ||
212 | ], | ||
213 | customAttrAssign: [/\)?\]?=/] | ||
214 | }, | ||
215 | |||
216 | /* | ||
217 | * Include polyfills or mocks for various node stuff | ||
218 | * Description: Node configuration | ||
219 | * | ||
220 | * See: https://webpack.github.io/docs/configuration.html#node | ||
221 | */ | ||
222 | node: { | ||
223 | global: 'window', | ||
224 | crypto: 'empty', | ||
225 | process: false, | ||
226 | module: false, | ||
227 | clearImmediate: false, | ||
228 | setImmediate: false | ||
229 | } | ||
230 | |||
231 | }) | ||