diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-13 12:16:00 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-13 12:16:00 +0100 |
commit | c16ce1de8e8c21ad2136335d3b0b7d230e6d2f24 (patch) | |
tree | e5177a26dae755833122c4ef73744c2a7f9b53fc /client/config/webpack.common.js | |
parent | 80deae8d198f6a376b477d780e76966f8fbb72ce (diff) | |
download | PeerTube-c16ce1de8e8c21ad2136335d3b0b7d230e6d2f24.tar.gz PeerTube-c16ce1de8e8c21ad2136335d3b0b7d230e6d2f24.tar.zst PeerTube-c16ce1de8e8c21ad2136335d3b0b7d230e6d2f24.zip |
Client: add basic aot support
Diffstat (limited to 'client/config/webpack.common.js')
-rw-r--r-- | client/config/webpack.common.js | 102 |
1 files changed, 81 insertions, 21 deletions
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 @@ | |||
1 | const webpack = require('webpack') | ||
2 | const helpers = require('./helpers') | 1 | const helpers = require('./helpers') |
3 | 2 | ||
4 | /* | 3 | /* |
5 | * Webpack Plugins | 4 | * Webpack Plugins |
6 | */ | 5 | */ |
7 | 6 | ||
8 | const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
9 | const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
10 | const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin | ||
11 | const AssetsPlugin = require('assets-webpack-plugin') | 7 | const AssetsPlugin = require('assets-webpack-plugin') |
8 | const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin') | ||
12 | const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin') | 9 | const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin') |
10 | const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin') | ||
11 | const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
12 | const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin | ||
13 | const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
13 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') | 14 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') |
14 | const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin') | 15 | const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin') |
16 | const ngcWebpack = require('ngc-webpack') | ||
17 | |||
15 | const WebpackNotifierPlugin = require('webpack-notifier') | 18 | const 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 | */ |
31 | module.exports = function (options) { | 34 | module.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 | } |