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 ProvidePlugin
= require('webpack/lib/ProvidePlugin')
12 const CommonsChunkPlugin
= require('webpack/lib/optimize/CommonsChunkPlugin')
13 const CopyWebpackPlugin
= require('copy-webpack-plugin')
14 const CheckerPlugin
= require('awesome-typescript-loader').CheckerPlugin
15 const HtmlWebpackPlugin
= require('html-webpack-plugin')
16 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
17 const ScriptExtHtmlWebpackPlugin
= require('script-ext-html-webpack-plugin')
18 const ngcWebpack
= require('ngc-webpack')
20 const WebpackNotifierPlugin
= require('webpack-notifier')
28 isDevServer: helpers
.isWebpackDevServer()
32 * Webpack configuration
34 * See: http://webpack.github.io/docs/configuration.html#cli
36 module
.exports = function (options
) {
37 const isProd
= options
.env
=== 'production'
43 * Cache generated modules and chunks to improve performance for multiple incremental builds.
44 * This is enabled by default in watch mode.
45 * You can pass false to disable it.
47 * See: http://webpack.github.io/docs/configuration.html#cache
52 * The entry point for the bundle
55 * See: http://webpack.github.io/docs/configuration.html#entry
58 'polyfills': './src/polyfills.browser.ts',
60 ? './src/main.browser.aot.ts'
61 : './src/main.browser.ts'
65 * Options affecting the resolving of modules.
67 * See: http://webpack.github.io/docs/configuration.html#resolve
71 * An array of extensions that should be used to resolve modules.
73 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
75 extensions: [ '.ts', '.js', '.json', '.scss' ],
77 modules: [ helpers
.root('src'), helpers
.root('node_modules') ],
80 'video.js': 'video.js/dist/alt/video.novtt'
85 * Options affecting the normal modules.
87 * See: http://webpack.github.io/docs/configuration.html#module
94 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
96 * See: https://github.com/s-panferov/awesome-typescript-loader
101 '@angularclass/hmr-loader?pretty=' + !isProd
+ '&prod=' + isProd
,
102 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
103 'angular2-template-loader',
105 loader: 'ng-router-loader',
107 loader: 'async-system',
113 exclude: [/\.(spec|e2e)\.ts$/]
117 * Json loader support for *.json files.
119 * See: https://github.com/webpack/json-loader
123 loader: 'json-loader'
127 test: /\.(sass|scss)$/,
128 use: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url-loader', 'sass-loader?sourceMap'],
129 exclude: [ helpers
.root('src', 'styles') ]
131 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
132 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
134 /* Raw loader support for *.html
135 * Returns file content as string
137 * See: https://github.com/webpack/raw-loader
141 loader: 'raw-loader',
142 exclude: [ helpers
.root('src/index.html'), helpers
.root('src/standalone/videos/embed.html') ]
150 * Add additional plugins to the compiler.
152 * See: http://webpack.github.io/docs/configuration.html#plugins
156 path: helpers
.root('dist'),
157 filename: 'webpack-assets.json',
162 * Plugin: ForkCheckerPlugin
163 * Description: Do type checking in a separate process, so webpack don't need to wait.
165 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
170 * Plugin: CommonsChunkPlugin
171 * Description: Shares common code between the pages.
172 * It identifies common modules and put them into a commons chunk.
174 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
175 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
177 new CommonsChunkPlugin({
179 chunks: ['polyfills']
182 // This enables tree shaking of the vendor modules
183 new CommonsChunkPlugin({
186 minChunks: module
=> /node_modules\//.test(module
.resource
)
189 // Specify the correct order the scripts will be injected in
190 new CommonsChunkPlugin({
191 name: ['polyfills', 'vendor'].reverse()
195 * Plugin: ContextReplacementPlugin
196 * Description: Provides context to Angular's use of System.import
198 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
199 * See: https://github.com/angular/angular/issues/11580
201 new ContextReplacementPlugin(
202 // The (\\|\/) piece accounts for path separators in *nix and Windows
203 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
204 helpers
.root('src'), // location of your src
206 // your Angular Async Route paths relative to this root directory
211 * Plugin: CopyWebpackPlugin
212 * Description: Copy files and directories in webpack.
214 * Copies project static assets.
216 * See: https://www.npmjs.com/package/copy-webpack-plugin
218 // Used by embed.html
219 new CopyWebpackPlugin([
225 from: 'node_modules/webtorrent/webtorrent.min.js',
226 to: 'assets/webtorrent'
229 from: 'node_modules/video.js/dist/video.min.js',
230 to: 'assets/video-js'
233 from: 'node_modules/video.js/dist/video-js.min.css',
234 to: 'assets/video-js'
237 from: 'node_modules/videojs-dock/dist/videojs-dock.min.js',
238 to: 'assets/video-js'
241 from: 'node_modules/videojs-dock/dist/videojs-dock.css',
242 to: 'assets/video-js'
245 from: 'src/standalone',
251 * Plugin: HtmlWebpackPlugin
252 * Description: Simplifies creation of HTML files to serve your webpack bundles.
253 * This is especially useful for webpack bundles that include a hash in the filename
254 * which changes every compilation.
256 * See: https://github.com/ampedandwired/html-webpack-plugin
258 new HtmlWebpackPlugin({
259 template: 'src/index.html',
260 title: METADATA
.title
,
261 chunksSortMode: 'dependency',
266 * Plugin: ScriptExtHtmlWebpackPlugin
267 * Description: Enhances html-webpack-plugin functionality
268 * with different deployment options for your scripts including:
270 * See: https://github.com/numical/script-ext-html-webpack-plugin
272 new ScriptExtHtmlWebpackPlugin({
273 sync: [ 'webtorrent.min.js' ],
274 defaultAttribute: 'defer'
277 new WebpackNotifierPlugin({ alwaysNotify: true }),
280 * Plugin LoaderOptionsPlugin (experimental)
282 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
284 new LoaderOptionsPlugin({
293 new NormalModuleReplacementPlugin(
294 /facade(\\|\/)async/,
295 helpers
.root('node_modules/@angular/core/src/facade/async.js')
297 new NormalModuleReplacementPlugin(
298 /facade(\\|\/)collection/,
299 helpers
.root('node_modules/@angular/core/src/facade/collection.js')
301 new NormalModuleReplacementPlugin(
302 /facade(\\|\/)errors/,
303 helpers
.root('node_modules/@angular/core/src/facade/errors.js')
305 new NormalModuleReplacementPlugin(
307 helpers
.root('node_modules/@angular/core/src/facade/lang.js')
309 new NormalModuleReplacementPlugin(
311 helpers
.root('node_modules/@angular/core/src/facade/math.js')
314 new ngcWebpack
.NgcWebpackPlugin({
316 tsConfig: helpers
.root('tsconfig.webpack.json'),
317 resourceOverride: helpers
.root('config/resource-override.js')
320 new BundleAnalyzerPlugin({
321 // Can be `server`, `static` or `disabled`.
322 // In `server` mode analyzer will start HTTP server to show bundle report.
323 // In `static` mode single HTML file with bundle report will be generated.
324 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
325 analyzerMode: 'static',
326 // Path to bundle report file that will be generated in `static` mode.
327 // Relative to bundles output directory.
328 reportFilename: 'report.html',
329 // Automatically open report in default browser
331 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
332 generateStatsFile: true,
333 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
334 // Relative to bundles output directory.
335 statsFilename: 'stats.json',
336 // Options for `stats.toJson()` method.
337 // For example you can exclude sources of your modules from stats file with `source: false` option.
338 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
340 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
346 * Include polyfills or mocks for various node stuff
347 * Description: Node configuration
349 * See: https://webpack.github.io/docs/configuration.html#node
356 clearImmediate: false,