diff options
Diffstat (limited to 'client/config/webpack.prod.js')
-rw-r--r-- | client/config/webpack.prod.js | 100 |
1 files changed, 37 insertions, 63 deletions
diff --git a/client/config/webpack.prod.js b/client/config/webpack.prod.js index ddc9343a7..b950d3fe5 100644 --- a/client/config/webpack.prod.js +++ b/client/config/webpack.prod.js | |||
@@ -14,22 +14,24 @@ const DefinePlugin = require('webpack/lib/DefinePlugin') | |||
14 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') | 14 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') |
15 | const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') | 15 | const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') |
16 | const OptimizeJsPlugin = require('optimize-js-plugin') | 16 | const OptimizeJsPlugin = require('optimize-js-plugin') |
17 | const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') | ||
18 | const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin') | 17 | const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin') |
19 | 18 | const ModuleConcatenationPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin') | |
19 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | ||
20 | /** | 20 | /** |
21 | * Webpack Constants | 21 | * Webpack Constants |
22 | */ | 22 | */ |
23 | const ENV = process.env.NODE_ENV = process.env.ENV = 'production' | 23 | const ENV = process.env.NODE_ENV = process.env.ENV = 'production' |
24 | const HOST = process.env.HOST || 'localhost' | 24 | const HOST = process.env.HOST || 'localhost' |
25 | const PORT = process.env.PORT || 8080 | 25 | const PORT = process.env.PORT || 8080 |
26 | const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, { | 26 | const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot') |
27 | const METADATA = { | ||
27 | host: HOST, | 28 | host: HOST, |
28 | port: PORT, | 29 | port: PORT, |
29 | ENV: ENV, | 30 | ENV: ENV, |
30 | HMR: false, | 31 | HMR: false, |
32 | AOT: AOT, | ||
31 | API_URL: '' | 33 | API_URL: '' |
32 | }) | 34 | } |
33 | 35 | ||
34 | module.exports = function (env) { | 36 | module.exports = function (env) { |
35 | return [ | 37 | return [ |
@@ -106,6 +108,7 @@ module.exports = function (env) { | |||
106 | * See: http://webpack.github.io/docs/configuration.html#plugins | 108 | * See: http://webpack.github.io/docs/configuration.html#plugins |
107 | */ | 109 | */ |
108 | plugins: [ | 110 | plugins: [ |
111 | new ModuleConcatenationPlugin(), | ||
109 | 112 | ||
110 | /** | 113 | /** |
111 | * Webpack plugin to optimize a JavaScript file for faster initial load | 114 | * Webpack plugin to optimize a JavaScript file for faster initial load |
@@ -142,12 +145,11 @@ module.exports = function (env) { | |||
142 | 'ENV': JSON.stringify(METADATA.ENV), | 145 | 'ENV': JSON.stringify(METADATA.ENV), |
143 | 'HMR': METADATA.HMR, | 146 | 'HMR': METADATA.HMR, |
144 | 'API_URL': JSON.stringify(METADATA.API_URL), | 147 | 'API_URL': JSON.stringify(METADATA.API_URL), |
148 | 'AOT': METADATA.AOT, | ||
145 | 'process.version': JSON.stringify(process.version), | 149 | 'process.version': JSON.stringify(process.version), |
146 | 'process.env': { | 150 | 'process.env.ENV': JSON.stringify(METADATA.ENV), |
147 | 'ENV': JSON.stringify(METADATA.ENV), | 151 | 'process.env.NODE_ENV': JSON.stringify(METADATA.ENV), |
148 | 'NODE_ENV': JSON.stringify(METADATA.ENV), | 152 | 'process.env.HMR': METADATA.HMR |
149 | 'HMR': METADATA.HMR | ||
150 | } | ||
151 | }), | 153 | }), |
152 | 154 | ||
153 | /** | 155 | /** |
@@ -159,44 +161,28 @@ module.exports = function (env) { | |||
159 | */ | 161 | */ |
160 | // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines | 162 | // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines |
161 | new UglifyJsPlugin({ | 163 | new UglifyJsPlugin({ |
162 | // beautify: true, //debug | 164 | parallel: true, |
163 | // mangle: false, //debug | 165 | uglifyOptions: { |
164 | // dead_code: false, //debug | 166 | ie8: false, |
165 | // unused: false, //debug | 167 | ecma: 6, |
166 | // deadCode: false, //debug | 168 | warnings: true, |
167 | // compress: { | 169 | mangle: true, |
168 | // screw_ie8: true, | 170 | output: { |
169 | // keep_fnames: true, | 171 | comments: false, |
170 | // drop_debugger: false, | 172 | beautify: false |
171 | // dead_code: false, | 173 | } |
172 | // unused: false | 174 | }, |
173 | // }, // debug | 175 | warnings: true |
174 | // comments: true, //debug | ||
175 | |||
176 | beautify: false, // prod | ||
177 | output: { | ||
178 | comments: false | ||
179 | }, // prod | ||
180 | mangle: { | ||
181 | screw_ie8: true | ||
182 | }, // prod | ||
183 | compress: { | ||
184 | screw_ie8: true, | ||
185 | warnings: false, | ||
186 | conditionals: true, | ||
187 | unused: true, | ||
188 | comparisons: true, | ||
189 | sequences: true, | ||
190 | dead_code: true, | ||
191 | evaluate: true, | ||
192 | if_return: true, | ||
193 | join_vars: true, | ||
194 | negate_iife: false // we need this for lazy v8 | ||
195 | } | ||
196 | }), | 176 | }), |
197 | 177 | ||
178 | /** | ||
179 | * Plugin: NormalModuleReplacementPlugin | ||
180 | * Description: Replace resources that matches resourceRegExp with newResource | ||
181 | * | ||
182 | * See: http://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin | ||
183 | */ | ||
198 | new NormalModuleReplacementPlugin( | 184 | new NormalModuleReplacementPlugin( |
199 | /angular2-hmr/, | 185 | /(angular2|@angularclass)((\\|\/)|-)hmr/, |
200 | helpers.root('config/empty.js') | 186 | helpers.root('config/empty.js') |
201 | ), | 187 | ), |
202 | 188 | ||
@@ -208,26 +194,14 @@ module.exports = function (env) { | |||
208 | new HashedModuleIdsPlugin(), | 194 | new HashedModuleIdsPlugin(), |
209 | 195 | ||
210 | /** | 196 | /** |
211 | * Plugin: IgnorePlugin | 197 | * AoT |
212 | * Description: Don’t generate modules for requests matching the provided RegExp. | ||
213 | * | ||
214 | * See: http://webpack.github.io/docs/list-of-plugins.html#ignoreplugin | ||
215 | */ | ||
216 | |||
217 | // new IgnorePlugin(/angular2-hmr/), | ||
218 | |||
219 | /** | ||
220 | * Plugin: CompressionPlugin | ||
221 | * Description: Prepares compressed versions of assets to serve | ||
222 | * them with Content-Encoding | ||
223 | * | ||
224 | * See: https://github.com/webpack/compression-webpack-plugin | ||
225 | */ | 198 | */ |
226 | // install compression-webpack-plugin | 199 | (AOT ? ( |
227 | // new CompressionPlugin({ | 200 | new NormalModuleReplacementPlugin( |
228 | // regExp: /\.css$|\.html$|\.js$|\.map$/, | 201 | /@angular(\\|\/)compiler/, |
229 | // threshold: 2 * 1024 | 202 | helpers.root('config/empty.js') |
230 | // }) | 203 | ) |
204 | ) : (new LoaderOptionsPlugin({}))), | ||
231 | 205 | ||
232 | /** | 206 | /** |
233 | * Plugin LoaderOptionsPlugin (experimental) | 207 | * Plugin LoaderOptionsPlugin (experimental) |