1 const helpers
= require('./helpers')
7 const AssetsPlugin
= require('assets-webpack-plugin')
8 const BundleAnalyzerPlugin
= require('webpack-bundle-analyzer').BundleAnalyzerPlugin
9 const NormalModuleReplacementPlugin
= require('webpack/lib/NormalModuleReplacementPlugin')
10 const ContextReplacementPlugin
= require('webpack/lib/ContextReplacementPlugin')
11 const CommonsChunkPlugin
= require('webpack/lib/optimize/CommonsChunkPlugin')
12 const CopyWebpackPlugin
= require('copy-webpack-plugin')
13 const CheckerPlugin
= require('awesome-typescript-loader').CheckerPlugin
14 const HtmlWebpackPlugin
= require('html-webpack-plugin')
15 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
16 const ScriptExtHtmlWebpackPlugin
= require('script-ext-html-webpack-plugin')
17 const ngcWebpack
= require('ngc-webpack')
19 const WebpackNotifierPlugin
= require('webpack-notifier')
27 isDevServer: helpers
.isWebpackDevServer()
31 * Webpack configuration
33 * See: http://webpack.github.io/docs/configuration.html#cli
35 module
.exports = function (options
) {
36 const isProd
= options
.env
=== 'production'
42 * Cache generated modules and chunks to improve performance for multiple incremental builds.
43 * This is enabled by default in watch mode.
44 * You can pass false to disable it.
46 * See: http://webpack.github.io/docs/configuration.html#cache
51 * The entry point for the bundle
54 * See: http://webpack.github.io/docs/configuration.html#entry
57 'polyfills': './src/polyfills.browser.ts',
59 ? './src/main.browser.aot.ts'
60 : './src/main.browser.ts'
64 * Options affecting the resolving of modules.
66 * See: http://webpack.github.io/docs/configuration.html#resolve
70 * An array of extensions that should be used to resolve modules.
72 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
74 extensions: [ '.ts', '.js', '.json', '.scss' ],
76 modules: [ helpers
.root('src'), helpers
.root('node_modules') ],
79 'video.js': 'video.js/dist/alt/video.novtt'
84 * Options affecting the normal modules.
86 * See: http://webpack.github.io/docs/configuration.html#module
93 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
95 * See: https://github.com/s-panferov/awesome-typescript-loader
100 '@angularclass/hmr-loader?pretty=' + !isProd
+ '&prod=' + isProd
,
101 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
102 'angular2-template-loader',
104 loader: 'ng-router-loader',
106 loader: 'async-system',
112 exclude: [/\.(spec|e2e)\.ts$/]
116 * Json loader support for *.json files.
118 * See: https://github.com/webpack/json-loader
122 loader: 'json-loader'
126 test: /\.(sass|scss)$/,
127 use: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url-loader', 'sass-loader?sourceMap'],
128 exclude: [ helpers
.root('src', 'styles') ]
130 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
131 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
133 /* Raw loader support for *.html
134 * Returns file content as string
136 * See: https://github.com/webpack/raw-loader
140 loader: 'raw-loader',
141 exclude: [ helpers
.root('src/index.html'), helpers
.root('src/standalone/videos/embed.html') ]
149 * Add additional plugins to the compiler.
151 * See: http://webpack.github.io/docs/configuration.html#plugins
155 path: helpers
.root('dist'),
156 filename: 'webpack-assets.json',
161 * Plugin: ForkCheckerPlugin
162 * Description: Do type checking in a separate process, so webpack don't need to wait.
164 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
169 * Plugin: CommonsChunkPlugin
170 * Description: Shares common code between the pages.
171 * It identifies common modules and put them into a commons chunk.
173 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
174 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
176 new CommonsChunkPlugin({
178 chunks: ['polyfills']
181 // This enables tree shaking of the vendor modules
182 new CommonsChunkPlugin({
185 minChunks: module
=> /node_modules\//.test(module
.resource
)
188 // Specify the correct order the scripts will be injected in
189 new CommonsChunkPlugin({
190 name: ['polyfills', 'vendor'].reverse()
194 * Plugin: ContextReplacementPlugin
195 * Description: Provides context to Angular's use of System.import
197 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
198 * See: https://github.com/angular/angular/issues/11580
200 new ContextReplacementPlugin(
201 // The (\\|\/) piece accounts for path separators in *nix and Windows
202 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
203 helpers
.root('src'), // location of your src
205 // your Angular Async Route paths relative to this root directory
210 * Plugin: CopyWebpackPlugin
211 * Description: Copy files and directories in webpack.
213 * Copies project static assets.
215 * See: https://www.npmjs.com/package/copy-webpack-plugin
217 // Used by embed.html
218 new CopyWebpackPlugin([
224 from: 'node_modules/webtorrent/webtorrent.min.js',
225 to: 'assets/webtorrent'
228 from: 'node_modules/video.js/dist/video.min.js',
229 to: 'assets/video-js'
232 from: 'node_modules/video.js/dist/video-js.min.css',
233 to: 'assets/video-js'
236 from: 'node_modules/videojs-dock/dist/videojs-dock.min.js',
237 to: 'assets/video-js'
240 from: 'node_modules/videojs-dock/dist/videojs-dock.css',
241 to: 'assets/video-js'
244 from: 'src/standalone',
250 * Plugin: HtmlWebpackPlugin
251 * Description: Simplifies creation of HTML files to serve your webpack bundles.
252 * This is especially useful for webpack bundles that include a hash in the filename
253 * which changes every compilation.
255 * See: https://github.com/ampedandwired/html-webpack-plugin
257 new HtmlWebpackPlugin({
258 template: 'src/index.html',
259 title: METADATA
.title
,
260 chunksSortMode: 'dependency',
265 * Plugin: ScriptExtHtmlWebpackPlugin
266 * Description: Enhances html-webpack-plugin functionality
267 * with different deployment options for your scripts including:
269 * See: https://github.com/numical/script-ext-html-webpack-plugin
271 new ScriptExtHtmlWebpackPlugin({
272 sync: [ 'webtorrent.min.js' ],
273 defaultAttribute: 'defer'
276 new WebpackNotifierPlugin({ alwaysNotify: true }),
279 * Plugin LoaderOptionsPlugin (experimental)
281 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
283 new LoaderOptionsPlugin({
292 new NormalModuleReplacementPlugin(
293 /facade(\\|\/)async/,
294 helpers
.root('node_modules/@angular/core/src/facade/async.js')
296 new NormalModuleReplacementPlugin(
297 /facade(\\|\/)collection/,
298 helpers
.root('node_modules/@angular/core/src/facade/collection.js')
300 new NormalModuleReplacementPlugin(
301 /facade(\\|\/)errors/,
302 helpers
.root('node_modules/@angular/core/src/facade/errors.js')
304 new NormalModuleReplacementPlugin(
306 helpers
.root('node_modules/@angular/core/src/facade/lang.js')
308 new NormalModuleReplacementPlugin(
310 helpers
.root('node_modules/@angular/core/src/facade/math.js')
313 new ngcWebpack
.NgcWebpackPlugin({
315 tsConfig: helpers
.root('tsconfig.webpack.json'),
316 resourceOverride: helpers
.root('config/resource-override.js')
319 new BundleAnalyzerPlugin({
320 // Can be `server`, `static` or `disabled`.
321 // In `server` mode analyzer will start HTTP server to show bundle report.
322 // In `static` mode single HTML file with bundle report will be generated.
323 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
324 analyzerMode: 'static',
325 // Path to bundle report file that will be generated in `static` mode.
326 // Relative to bundles output directory.
327 reportFilename: 'report.html',
328 // Automatically open report in default browser
330 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
331 generateStatsFile: true,
332 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
333 // Relative to bundles output directory.
334 statsFilename: 'stats.json',
335 // Options for `stats.toJson()` method.
336 // For example you can exclude sources of your modules from stats file with `source: false` option.
337 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
339 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
345 * Include polyfills or mocks for various node stuff
346 * Description: Node configuration
348 * See: https://webpack.github.io/docs/configuration.html#node
355 clearImmediate: false,