1 const helpers = require('./helpers')
7 const AssetsPlugin = require('assets-webpack-plugin')
8 const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
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')
14 const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
15 const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
16 const ngcWebpack = require('ngc-webpack')
18 const WebpackNotifierPlugin = require('webpack-notifier')
26 isDevServer: helpers.isWebpackDevServer()
30 * Webpack configuration
32 * See: http://webpack.github.io/docs/configuration.html#cli
34 module.exports = function (options) {
35 const isProd = options.env === 'production'
41 * Cache generated modules and chunks to improve performance for multiple incremental builds.
42 * This is enabled by default in watch mode.
43 * You can pass false to disable it.
45 * See: http://webpack.github.io/docs/configuration.html#cache
50 * The entry point for the bundle
53 * See: http://webpack.github.io/docs/configuration.html#entry
56 'polyfills': './src/polyfills.browser.ts',
58 ? './src/main.browser.aot.ts'
59 : './src/main.browser.ts'
63 * Options affecting the resolving of modules.
65 * See: http://webpack.github.io/docs/configuration.html#resolve
69 * An array of extensions that should be used to resolve modules.
71 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
73 extensions: [ '.ts', '.js', '.json', '.scss' ],
75 modules: [ helpers.root('src'), helpers.root('node_modules') ],
78 'video.js': 'video.js/dist/alt/video.novtt'
83 * Options affecting the normal modules.
85 * See: http://webpack.github.io/docs/configuration.html#module
92 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
94 * See: https://github.com/s-panferov/awesome-typescript-loader
99 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
100 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
101 'angular2-template-loader',
103 loader: 'ng-router-loader',
105 loader: 'async-system',
111 exclude: [/\.(spec|e2e)\.ts$/]
115 * Json loader support for *.json files.
117 * See: https://github.com/webpack/json-loader
121 loader: 'json-loader'
125 test: /\.(sass|scss)$/,
126 use: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url-loader', 'sass-loader?sourceMap'],
127 exclude: [ helpers.root('src', 'styles') ]
129 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
130 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
132 /* Raw loader support for *.html
133 * Returns file content as string
135 * See: https://github.com/webpack/raw-loader
139 loader: 'raw-loader',
140 exclude: [ helpers.root('src/index.html'), helpers.root('src/standalone/videos/embed.html') ]
148 * Add additional plugins to the compiler.
150 * See: http://webpack.github.io/docs/configuration.html#plugins
154 path: helpers.root('dist'),
155 filename: 'webpack-assets.json',
160 * Plugin: ForkCheckerPlugin
161 * Description: Do type checking in a separate process, so webpack don't need to wait.
163 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
168 * Plugin: CommonsChunkPlugin
169 * Description: Shares common code between the pages.
170 * It identifies common modules and put them into a commons chunk.
172 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
173 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
175 new CommonsChunkPlugin({
177 chunks: ['polyfills']
180 // This enables tree shaking of the vendor modules
181 new CommonsChunkPlugin({
184 minChunks: module => /node_modules\//.test(module.resource)
187 // Specify the correct order the scripts will be injected in
188 new CommonsChunkPlugin({
189 name: ['polyfills', 'vendor'].reverse()
193 * Plugin: ContextReplacementPlugin
194 * Description: Provides context to Angular's use of System.import
196 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
197 * See: https://github.com/angular/angular/issues/11580
199 new ContextReplacementPlugin(
200 // The (\\|\/) piece accounts for path separators in *nix and Windows
201 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
202 helpers.root('src'), // location of your src
204 // your Angular Async Route paths relative to this root directory
209 * Plugin: CopyWebpackPlugin
210 * Description: Copy files and directories in webpack.
212 * Copies project static assets.
214 * See: https://www.npmjs.com/package/copy-webpack-plugin
216 // Used by embed.html
217 new CopyWebpackPlugin([
223 from: 'node_modules/webtorrent/webtorrent.min.js',
224 to: 'assets/webtorrent'
227 from: 'node_modules/video.js/dist/video.min.js',
228 to: 'assets/video-js'
231 from: 'node_modules/video.js/dist/video-js.min.css',
232 to: 'assets/video-js'
235 from: 'node_modules/videojs-dock/dist/videojs-dock.min.js',
236 to: 'assets/video-js'
239 from: 'node_modules/videojs-dock/dist/videojs-dock.css',
240 to: 'assets/video-js'
243 from: 'src/standalone',
249 * Plugin: HtmlWebpackPlugin
250 * Description: Simplifies creation of HTML files to serve your webpack bundles.
251 * This is especially useful for webpack bundles that include a hash in the filename
252 * which changes every compilation.
254 * See: https://github.com/ampedandwired/html-webpack-plugin
256 new HtmlWebpackPlugin({
257 template: 'src/index.html',
258 title: METADATA.title,
259 chunksSortMode: 'dependency',
264 * Plugin: ScriptExtHtmlWebpackPlugin
265 * Description: Enhances html-webpack-plugin functionality
266 * with different deployment options for your scripts including:
268 * See: https://github.com/numical/script-ext-html-webpack-plugin
270 new ScriptExtHtmlWebpackPlugin({
271 sync: [ 'webtorrent.min.js' ],
272 defaultAttribute: 'defer'
275 new WebpackNotifierPlugin({ alwaysNotify: true }),
278 * Plugin LoaderOptionsPlugin (experimental)
280 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
282 new LoaderOptionsPlugin({
291 new NormalModuleReplacementPlugin(
292 /facade(\\|\/)async/,
293 helpers.root('node_modules/@angular/core/src/facade/async.js')
295 new NormalModuleReplacementPlugin(
296 /facade(\\|\/)collection/,
297 helpers.root('node_modules/@angular/core/src/facade/collection.js')
299 new NormalModuleReplacementPlugin(
300 /facade(\\|\/)errors/,
301 helpers.root('node_modules/@angular/core/src/facade/errors.js')
303 new NormalModuleReplacementPlugin(
305 helpers.root('node_modules/@angular/core/src/facade/lang.js')
307 new NormalModuleReplacementPlugin(
309 helpers.root('node_modules/@angular/core/src/facade/math.js')
312 new ngcWebpack.NgcWebpackPlugin({
314 tsConfig: helpers.root('tsconfig.webpack.json'),
315 resourceOverride: helpers.root('config/resource-override.js')
320 * Include polyfills or mocks for various node stuff
321 * Description: Node configuration
323 * See: https://webpack.github.io/docs/configuration.html#node
330 clearImmediate: false,