]>
Commit | Line | Data |
---|---|---|
b20b5fed C |
1 | /** |
2 | * @author: @AngularClass | |
3 | */ | |
4 | ||
5 | const helpers = require('./helpers') | |
6 | const webpackMerge = require('webpack-merge') // used to merge webpack configs | |
7 | const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev | |
202e7223 | 8 | const videoEmbedConfig = require('./webpack.video-embed.js') |
b20b5fed C |
9 | |
10 | /** | |
11 | * Webpack Plugins | |
12 | */ | |
b20b5fed | 13 | const DefinePlugin = require('webpack/lib/DefinePlugin') |
4d19d2f1 | 14 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') |
c16ce1de | 15 | const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') |
f7ac0f84 | 16 | const OptimizeJsPlugin = require('optimize-js-plugin') |
b20b5fed | 17 | const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') |
8635a2c7 | 18 | const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin') |
b20b5fed C |
19 | |
20 | /** | |
21 | * Webpack Constants | |
22 | */ | |
23 | const ENV = process.env.NODE_ENV = process.env.ENV = 'production' | |
24 | const HOST = process.env.HOST || 'localhost' | |
25 | const PORT = process.env.PORT || 8080 | |
2e92c10b | 26 | const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, { |
b20b5fed C |
27 | host: HOST, |
28 | port: PORT, | |
29 | ENV: ENV, | |
1840c2f7 C |
30 | HMR: false, |
31 | API_URL: '' | |
b20b5fed C |
32 | }) |
33 | ||
ad22074a | 34 | module.exports = function (env) { |
202e7223 C |
35 | return [ |
36 | videoEmbedConfig({ env: ENV }), | |
4d19d2f1 | 37 | |
202e7223 | 38 | webpackMerge(commonConfig({ env: ENV }), { |
ad22074a | 39 | /** |
202e7223 | 40 | * Developer tool to enhance debugging |
4d19d2f1 | 41 | * |
202e7223 C |
42 | * See: http://webpack.github.io/docs/configuration.html#devtool |
43 | * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps | |
4d19d2f1 | 44 | */ |
202e7223 | 45 | devtool: 'source-map', |
ad22074a C |
46 | |
47 | /** | |
202e7223 | 48 | * Options affecting the output of the compilation. |
4d19d2f1 | 49 | * |
202e7223 | 50 | * See: http://webpack.github.io/docs/configuration.html#output |
4d19d2f1 | 51 | */ |
202e7223 | 52 | output: { |
ad22074a | 53 | |
202e7223 C |
54 | /** |
55 | * The output directory as absolute path (required). | |
56 | * | |
57 | * See: http://webpack.github.io/docs/configuration.html#output-path | |
58 | */ | |
59 | path: helpers.root('dist'), | |
ad22074a | 60 | |
202e7223 C |
61 | /** |
62 | * Specifies the name of each output file on disk. | |
63 | * IMPORTANT: You must not specify an absolute path here! | |
64 | * | |
65 | * See: http://webpack.github.io/docs/configuration.html#output-filename | |
66 | */ | |
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', | |
ad22074a | 76 | |
202e7223 C |
77 | /** |
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', | |
ad22074a | 84 | |
202e7223 C |
85 | publicPath: '/client/' |
86 | }, | |
87 | ||
88 | module: { | |
89 | rules: [ | |
90 | { | |
91 | test: /junk\/index\.js$/, | |
92 | // exclude: /(node_modules|bower_components)/, | |
93 | use: { | |
94 | loader: 'babel-loader', | |
95 | options: { | |
96 | presets: [ 'env' ] | |
97 | } | |
f627b712 C |
98 | } |
99 | } | |
202e7223 C |
100 | ] |
101 | }, | |
ad22074a | 102 | |
f7ac0f84 | 103 | /** |
202e7223 | 104 | * Add additional plugins to the compiler. |
f7ac0f84 | 105 | * |
202e7223 | 106 | * See: http://webpack.github.io/docs/configuration.html#plugins |
f7ac0f84 | 107 | */ |
202e7223 | 108 | plugins: [ |
f7ac0f84 | 109 | |
202e7223 C |
110 | /** |
111 | * Webpack plugin to optimize a JavaScript file for faster initial load | |
112 | * by wrapping eagerly-invoked functions. | |
113 | * | |
114 | * See: https://github.com/vigneshshanmugam/optimize-js-plugin | |
115 | */ | |
f7ac0f84 | 116 | |
202e7223 C |
117 | new OptimizeJsPlugin({ |
118 | sourceMap: false | |
119 | }), | |
ad22074a | 120 | |
202e7223 C |
121 | /** |
122 | * Plugin: DedupePlugin | |
123 | * Description: Prevents the inclusion of duplicate code into your bundle | |
124 | * and instead applies a copy of the function at runtime. | |
125 | * | |
126 | * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin | |
127 | * See: https://github.com/webpack/docs/wiki/optimization#deduplication | |
128 | */ | |
129 | // new DedupePlugin(), | |
130 | ||
131 | /** | |
132 | * Plugin: DefinePlugin | |
133 | * Description: Define free variables. | |
134 | * Useful for having development builds with debug logging or adding global constants. | |
135 | * | |
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({ | |
ad22074a | 142 | 'ENV': JSON.stringify(METADATA.ENV), |
202e7223 C |
143 | 'HMR': METADATA.HMR, |
144 | 'API_URL': JSON.stringify(METADATA.API_URL), | |
145 | 'process.version': JSON.stringify(process.version), | |
146 | 'process.env': { | |
147 | 'ENV': JSON.stringify(METADATA.ENV), | |
148 | 'NODE_ENV': JSON.stringify(METADATA.ENV), | |
149 | 'HMR': METADATA.HMR | |
150 | } | |
151 | }), | |
f627b712 | 152 | |
202e7223 C |
153 | /** |
154 | * Plugin: UglifyJsPlugin | |
155 | * Description: Minimize all JavaScript output of chunks. | |
156 | * Loaders are switched into minimizing mode. | |
157 | * | |
158 | * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin | |
159 | */ | |
160 | // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines | |
161 | new UglifyJsPlugin({ | |
162 | // beautify: true, //debug | |
163 | // mangle: false, //debug | |
164 | // dead_code: false, //debug | |
165 | // unused: false, //debug | |
166 | // deadCode: false, //debug | |
167 | // compress: { | |
168 | // screw_ie8: true, | |
169 | // keep_fnames: true, | |
170 | // drop_debugger: false, | |
171 | // dead_code: false, | |
172 | // unused: false | |
173 | // }, // debug | |
174 | // comments: true, //debug | |
ad22074a | 175 | |
202e7223 C |
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 | }), | |
ad22074a | 197 | |
202e7223 C |
198 | new NormalModuleReplacementPlugin( |
199 | /angular2-hmr/, | |
200 | helpers.root('config/empty.js') | |
201 | ), | |
ad22074a | 202 | |
202e7223 C |
203 | new NormalModuleReplacementPlugin( |
204 | /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/, | |
205 | helpers.root('config/empty.js') | |
206 | ), | |
c16ce1de | 207 | |
202e7223 | 208 | new HashedModuleIdsPlugin(), |
c16ce1de | 209 | |
202e7223 C |
210 | /** |
211 | * Plugin: IgnorePlugin | |
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 | */ | |
4d19d2f1 | 216 | |
202e7223 | 217 | // new IgnorePlugin(/angular2-hmr/), |
4d19d2f1 | 218 | |
202e7223 C |
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 | */ | |
226 | // install compression-webpack-plugin | |
227 | // new CompressionPlugin({ | |
228 | // regExp: /\.css$|\.html$|\.js$|\.map$/, | |
229 | // threshold: 2 * 1024 | |
230 | // }) | |
b20b5fed | 231 | |
202e7223 C |
232 | /** |
233 | * Plugin LoaderOptionsPlugin (experimental) | |
234 | * | |
235 | * See: https://gist.github.com/sokra/27b24881210b56bbaff7 | |
236 | */ | |
237 | new LoaderOptionsPlugin({ | |
238 | minimize: true, | |
239 | debug: false, | |
240 | options: { | |
b20b5fed | 241 | |
202e7223 C |
242 | /** |
243 | * Static analysis linter for TypeScript advanced options configuration | |
244 | * Description: An extensible linter for the TypeScript language. | |
245 | * | |
246 | * See: https://github.com/wbuchwalter/tslint-loader | |
247 | */ | |
248 | tslint: { | |
249 | emitErrors: true, | |
250 | failOnHint: true, | |
251 | resourcePath: 'src' | |
252 | }, | |
b20b5fed | 253 | |
202e7223 C |
254 | /** |
255 | * Html loader advanced options | |
256 | * | |
257 | * See: https://github.com/webpack/html-loader#advanced-options | |
258 | */ | |
259 | // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor | |
260 | htmlLoader: { | |
261 | minimize: true, | |
262 | removeAttributeQuotes: false, | |
263 | caseSensitive: true, | |
264 | customAttrSurround: [ | |
265 | [/#/, /(?:)/], | |
266 | [/\*/, /(?:)/], | |
267 | [/\[?\(?/, /(?:)/] | |
268 | ], | |
269 | customAttrAssign: [/\)?]?=/] | |
270 | }, | |
4d19d2f1 | 271 | |
202e7223 C |
272 | // FIXME: Remove |
273 | // https://github.com/bholloway/resolve-url-loader/issues/36 | |
274 | // https://github.com/jtangelder/sass-loader/issues/289 | |
275 | context: __dirname, | |
276 | output: { | |
277 | path: helpers.root('dist') | |
278 | } | |
4d19d2f1 | 279 | } |
202e7223 C |
280 | }) |
281 | ], | |
ad22074a | 282 | |
202e7223 C |
283 | /* |
284 | * Include polyfills or mocks for various node stuff | |
285 | * Description: Node configuration | |
286 | * | |
287 | * See: https://webpack.github.io/docs/configuration.html#node | |
288 | */ | |
289 | node: { | |
290 | global: true, | |
291 | crypto: 'empty', | |
292 | fs: 'empty', | |
293 | process: true, | |
294 | module: false, | |
295 | clearImmediate: false, | |
296 | setImmediate: false | |
297 | } | |
ad22074a | 298 | |
202e7223 C |
299 | }) |
300 | ] | |
ad22074a | 301 | } |