aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/config
diff options
context:
space:
mode:
Diffstat (limited to 'client/config')
-rw-r--r--client/config/empty.js8
-rw-r--r--client/config/helpers.js9
-rw-r--r--client/config/resource-override.js0
-rw-r--r--client/config/webpack.common.js102
-rw-r--r--client/config/webpack.dev.js3
-rw-r--r--client/config/webpack.prod.js68
6 files changed, 155 insertions, 35 deletions
diff --git a/client/config/empty.js b/client/config/empty.js
new file mode 100644
index 000000000..33acae188
--- /dev/null
+++ b/client/config/empty.js
@@ -0,0 +1,8 @@
1module.exports = {
2 NgProbeToken: {},
3 HmrState: function () {},
4 _createConditionalRootRenderer: function (rootRenderer, extraTokens, coreTokens) {
5 return rootRenderer
6 },
7 __platform_browser_private__: {}
8}
diff --git a/client/config/helpers.js b/client/config/helpers.js
index 6268d2628..ca5923472 100644
--- a/client/config/helpers.js
+++ b/client/config/helpers.js
@@ -1,13 +1,17 @@
1const path = require('path') 1const path = require('path')
2 2
3// Helper functions
3const ROOT = path.resolve(__dirname, '..') 4const ROOT = path.resolve(__dirname, '..')
4 5const EVENT = process.env.npm_lifecycle_event || ''
5console.log('root directory:', root() + '\n')
6 6
7function hasProcessFlag (flag) { 7function hasProcessFlag (flag) {
8 return process.argv.join('').indexOf(flag) > -1 8 return process.argv.join('').indexOf(flag) > -1
9} 9}
10 10
11function hasNpmFlag (flag) {
12 return EVENT.includes(flag)
13}
14
11function isWebpackDevServer () { 15function isWebpackDevServer () {
12 return process.argv[1] && !!(/webpack-dev-server$/.exec(process.argv[1])) 16 return process.argv[1] && !!(/webpack-dev-server$/.exec(process.argv[1]))
13} 17}
@@ -18,5 +22,6 @@ function root (args) {
18} 22}
19 23
20exports.hasProcessFlag = hasProcessFlag 24exports.hasProcessFlag = hasProcessFlag
25exports.hasNpmFlag = hasNpmFlag
21exports.isWebpackDevServer = isWebpackDevServer 26exports.isWebpackDevServer = isWebpackDevServer
22exports.root = root 27exports.root = root
diff --git a/client/config/resource-override.js b/client/config/resource-override.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/client/config/resource-override.js
diff --git a/client/config/webpack.common.js b/client/config/webpack.common.js
index 7631af6b9..09d6f72b5 100644
--- a/client/config/webpack.common.js
+++ b/client/config/webpack.common.js
@@ -1,17 +1,20 @@
1const webpack = require('webpack')
2const helpers = require('./helpers') 1const helpers = require('./helpers')
3 2
4/* 3/*
5 * Webpack Plugins 4 * Webpack Plugins
6 */ 5 */
7 6
8const CopyWebpackPlugin = require('copy-webpack-plugin')
9const HtmlWebpackPlugin = require('html-webpack-plugin')
10const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
11const AssetsPlugin = require('assets-webpack-plugin') 7const AssetsPlugin = require('assets-webpack-plugin')
8const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
12const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin') 9const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
10const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
11const CopyWebpackPlugin = require('copy-webpack-plugin')
12const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
13const HtmlWebpackPlugin = require('html-webpack-plugin')
13const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') 14const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
14const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin') 15const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
16const ngcWebpack = require('ngc-webpack')
17
15const WebpackNotifierPlugin = require('webpack-notifier') 18const WebpackNotifierPlugin = require('webpack-notifier')
16 19
17/* 20/*
@@ -29,7 +32,8 @@ const METADATA = {
29 * See: http://webpack.github.io/docs/configuration.html#cli 32 * See: http://webpack.github.io/docs/configuration.html#cli
30 */ 33 */
31module.exports = function (options) { 34module.exports = function (options) {
32 var isProd = options.env === 'production' 35 const isProd = options.env === 'production'
36 const AOT = isProd
33 37
34 return { 38 return {
35 39
@@ -49,9 +53,10 @@ module.exports = function (options) {
49 * See: http://webpack.github.io/docs/configuration.html#entry 53 * See: http://webpack.github.io/docs/configuration.html#entry
50 */ 54 */
51 entry: { 55 entry: {
52 'polyfills': './src/polyfills.ts', 56 'polyfills': './src/polyfills.browser.ts',
53 'vendor': './src/vendor.ts', 57 'main': AOT
54 'main': './src/main.ts' 58 ? './src/main.browser.aot.ts'
59 : './src/main.browser.ts'
55 }, 60 },
56 61
57 /* 62 /*
@@ -67,7 +72,7 @@ module.exports = function (options) {
67 */ 72 */
68 extensions: [ '.ts', '.js', '.json', '.scss' ], 73 extensions: [ '.ts', '.js', '.json', '.scss' ],
69 74
70 modules: [helpers.root('src'), 'node_modules'], 75 modules: [ helpers.root('src'), helpers.root('node_modules') ],
71 76
72 alias: { 77 alias: {
73 'video.js': 'video.js/dist/alt/video.novtt' 78 'video.js': 'video.js/dist/alt/video.novtt'
@@ -90,10 +95,18 @@ module.exports = function (options) {
90 */ 95 */
91 { 96 {
92 test: /\.ts$/, 97 test: /\.ts$/,
93 loaders: [ 98 use: [
94 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd, 99 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
95 'awesome-typescript-loader', 100 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
96 'angular2-template-loader' 101 'angular2-template-loader',
102 {
103 loader: 'ng-router-loader',
104 options: {
105 loader: 'async-system',
106 genDir: 'compiled',
107 aot: AOT
108 }
109 }
97 ], 110 ],
98 exclude: [/\.(spec|e2e)\.ts$/] 111 exclude: [/\.(spec|e2e)\.ts$/]
99 }, 112 },
@@ -110,10 +123,11 @@ module.exports = function (options) {
110 123
111 { 124 {
112 test: /\.(sass|scss)$/, 125 test: /\.(sass|scss)$/,
113 loaders: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url', 'sass-loader?sourceMap'] 126 use: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url-loader', 'sass-loader?sourceMap'],
127 exclude: [ helpers.root('src', 'styles') ]
114 }, 128 },
115 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url?limit=10000&minetype=application/font-woff' }, 129 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
116 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file' }, 130 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
117 131
118 /* Raw loader support for *.html 132 /* Raw loader support for *.html
119 * Returns file content as string 133 * Returns file content as string
@@ -148,7 +162,7 @@ module.exports = function (options) {
148 * 162 *
149 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse 163 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
150 */ 164 */
151 new ForkCheckerPlugin(), 165 new CheckerPlugin(),
152 166
153 /* 167 /*
154 * Plugin: CommonsChunkPlugin 168 * Plugin: CommonsChunkPlugin
@@ -158,8 +172,21 @@ module.exports = function (options) {
158 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin 172 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
159 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app 173 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
160 */ 174 */
161 new webpack.optimize.CommonsChunkPlugin({ 175 new CommonsChunkPlugin({
162 name: [ 'polyfills', 'vendor' ].reverse() 176 name: 'polyfills',
177 chunks: ['polyfills']
178 }),
179
180 // This enables tree shaking of the vendor modules
181 new CommonsChunkPlugin({
182 name: 'vendor',
183 chunks: ['main'],
184 minChunks: module => /node_modules\//.test(module.resource)
185 }),
186
187 // Specify the correct order the scripts will be injected in
188 new CommonsChunkPlugin({
189 name: ['polyfills', 'vendor'].reverse()
163 }), 190 }),
164 191
165 /** 192 /**
@@ -171,8 +198,11 @@ module.exports = function (options) {
171 */ 198 */
172 new ContextReplacementPlugin( 199 new ContextReplacementPlugin(
173 // The (\\|\/) piece accounts for path separators in *nix and Windows 200 // The (\\|\/) piece accounts for path separators in *nix and Windows
174 /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/, 201 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
175 helpers.root('src') // location of your src 202 helpers.root('src'), // location of your src
203 {
204 // your Angular Async Route paths relative to this root directory
205 }
176 ), 206 ),
177 207
178 /* 208 /*
@@ -255,6 +285,34 @@ module.exports = function (options) {
255 precision: 10 285 precision: 10
256 } 286 }
257 } 287 }
288 }),
289
290 // Fix Angular 2
291 new NormalModuleReplacementPlugin(
292 /facade(\\|\/)async/,
293 helpers.root('node_modules/@angular/core/src/facade/async.js')
294 ),
295 new NormalModuleReplacementPlugin(
296 /facade(\\|\/)collection/,
297 helpers.root('node_modules/@angular/core/src/facade/collection.js')
298 ),
299 new NormalModuleReplacementPlugin(
300 /facade(\\|\/)errors/,
301 helpers.root('node_modules/@angular/core/src/facade/errors.js')
302 ),
303 new NormalModuleReplacementPlugin(
304 /facade(\\|\/)lang/,
305 helpers.root('node_modules/@angular/core/src/facade/lang.js')
306 ),
307 new NormalModuleReplacementPlugin(
308 /facade(\\|\/)math/,
309 helpers.root('node_modules/@angular/core/src/facade/math.js')
310 ),
311
312 new ngcWebpack.NgcWebpackPlugin({
313 disabled: !AOT,
314 tsConfig: helpers.root('tsconfig.webpack.json'),
315 resourceOverride: helpers.root('config/resource-override.js')
258 }) 316 })
259 ], 317 ],
260 318
@@ -270,7 +328,9 @@ module.exports = function (options) {
270 process: true, 328 process: true,
271 module: false, 329 module: false,
272 clearImmediate: false, 330 clearImmediate: false,
273 setImmediate: false 331 setImmediate: false,
332 setInterval: false,
333 setTimeout: false
274 } 334 }
275 } 335 }
276} 336}
diff --git a/client/config/webpack.dev.js b/client/config/webpack.dev.js
index 964ea56a5..cea9d0306 100644
--- a/client/config/webpack.dev.js
+++ b/client/config/webpack.dev.js
@@ -1,6 +1,7 @@
1const helpers = require('./helpers') 1const helpers = require('./helpers')
2const webpackMerge = require('webpack-merge') // used to merge webpack configs 2const webpackMerge = require('webpack-merge') // used to merge webpack configs
3const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev 3const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
4const path = require('path')
4 5
5/** 6/**
6 * Webpack Plugins 7 * Webpack Plugins
@@ -29,7 +30,7 @@ const METADATA = webpackMerge(commonConfig({env: ENV}).metadata, {
29 * See: http://webpack.github.io/docs/configuration.html#cli 30 * See: http://webpack.github.io/docs/configuration.html#cli
30 */ 31 */
31module.exports = function (env) { 32module.exports = function (env) {
32 return webpackMerge(commonConfig({env: ENV}), { 33 return webpackMerge(commonConfig({ env: ENV }), {
33 /** 34 /**
34 * Developer tool to enhance debugging 35 * Developer tool to enhance debugging
35 * 36 *
diff --git a/client/config/webpack.prod.js b/client/config/webpack.prod.js
index 447d47415..64d776f24 100644
--- a/client/config/webpack.prod.js
+++ b/client/config/webpack.prod.js
@@ -9,14 +9,15 @@ 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')
13const DefinePlugin = require('webpack/lib/DefinePlugin') 12const DefinePlugin = require('webpack/lib/DefinePlugin')
14const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') 13const ExtractTextPlugin = require('extract-text-webpack-plugin')
14const IgnorePlugin = require('webpack/lib/IgnorePlugin')
15const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') 15const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
16// const IgnorePlugin = require('webpack/lib/IgnorePlugin') 16const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
17// const DedupePlugin = require('webpack/lib/optimize/DedupePlugin') 17const ProvidePlugin = require('webpack/lib/ProvidePlugin')
18const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin') 18const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
19const WebpackMd5Hash = require('webpack-md5-hash') 19const WebpackMd5Hash = require('webpack-md5-hash')
20const V8LazyParseWebpackPlugin = require('v8-lazy-parse-webpack-plugin')
20 21
21/** 22/**
22 * Webpack Constants 23 * Webpack Constants
@@ -154,22 +155,67 @@ module.exports = function (env) {
154 // comments: true, //debug 155 // comments: true, //debug
155 156
156 beautify: false, // prod 157 beautify: false, // prod
158 output: {
159 comments: false
160 }, // prod
157 mangle: { 161 mangle: {
158 screw_ie8: true, 162 screw_ie8: true
159 keep_fnames: true
160 }, // prod 163 }, // prod
161 compress: { 164 compress: {
162 screw_ie8: true, 165 screw_ie8: true,
163 warnings: false 166 warnings: false,
164 }, // prod 167 conditionals: true,
165 comments: false // prod 168 unused: true,
169 comparisons: true,
170 sequences: true,
171 dead_code: true,
172 evaluate: true,
173 if_return: true,
174 join_vars: true,
175 negate_iife: false // we need this for lazy v8
176 }
166 }), 177 }),
167 178
168 new NormalModuleReplacementPlugin( 179 new NormalModuleReplacementPlugin(
169 /angular2-hmr/, 180 /angular2-hmr/,
170 helpers.root('config/modules/angular2-hmr-prod.js') 181 helpers.root('config/empty.js')
171 ), 182 ),
172 183
184 new NormalModuleReplacementPlugin(
185 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
186 helpers.root('config/empty.js')
187 ),
188
189 // AoT
190 // new NormalModuleReplacementPlugin(
191 // /@angular(\\|\/)upgrade/,
192 // helpers.root('config/empty.js')
193 // ),
194 // new NormalModuleReplacementPlugin(
195 // /@angular(\\|\/)compiler/,
196 // helpers.root('config/empty.js')
197 // ),
198 // new NormalModuleReplacementPlugin(
199 // /@angular(\\|\/)platform-browser-dynamic/,
200 // helpers.root('config/empty.js')
201 // ),
202 // new NormalModuleReplacementPlugin(
203 // /dom(\\|\/)debug(\\|\/)ng_probe/,
204 // helpers.root('config/empty.js')
205 // ),
206 // new NormalModuleReplacementPlugin(
207 // /dom(\\|\/)debug(\\|\/)by/,
208 // helpers.root('config/empty.js')
209 // ),
210 // new NormalModuleReplacementPlugin(
211 // /src(\\|\/)debug(\\|\/)debug_node/,
212 // helpers.root('config/empty.js')
213 // ),
214 // new NormalModuleReplacementPlugin(
215 // /src(\\|\/)debug(\\|\/)debug_renderer/,
216 // helpers.root('config/empty.js')
217 // ),
218
173 /** 219 /**
174 * Plugin: IgnorePlugin 220 * Plugin: IgnorePlugin
175 * Description: Don’t generate modules for requests matching the provided RegExp. 221 * Description: Don’t generate modules for requests matching the provided RegExp.
@@ -228,7 +274,7 @@ module.exports = function (env) {
228 [/\*/, /(?:)/], 274 [/\*/, /(?:)/],
229 [/\[?\(?/, /(?:)/] 275 [/\[?\(?/, /(?:)/]
230 ], 276 ],
231 customAttrAssign: [/\)?]?=/] 277 customAttrAssign: [/\)?\]?=/]
232 }, 278 },
233 279
234 // FIXME: Remove 280 // FIXME: Remove