1 const helpers
= require('./helpers')
7 const AssetsPlugin
= require('assets-webpack-plugin')
8 const BundleAnalyzerPlugin
= require('webpack-bundle-analyzer').BundleAnalyzerPlugin
9 const ContextReplacementPlugin
= require('webpack/lib/ContextReplacementPlugin')
10 const CommonsChunkPlugin
= require('webpack/lib/optimize/CommonsChunkPlugin')
11 const CheckerPlugin
= require('awesome-typescript-loader').CheckerPlugin
12 const HtmlWebpackPlugin
= require('html-webpack-plugin')
13 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
14 const ScriptExtHtmlWebpackPlugin
= require('script-ext-html-webpack-plugin')
15 const ngcWebpack
= require('ngc-webpack')
17 const WebpackNotifierPlugin
= require('webpack-notifier')
19 const HMR
= helpers
.hasProcessFlag('hot')
20 const AOT
= process
.env
.BUILD_AOT
|| helpers
.hasNpmFlag('aot')
24 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') ]
79 * Options affecting the normal modules.
81 * See: http://webpack.github.io/docs/configuration.html#module
88 * Typescript loader support for .ts and Angular async routes via .async.ts
90 * See: https://github.com/s-panferov/awesome-typescript-loader
96 loader: 'ng-router-loader',
98 loader: 'async-import',
104 loader: 'awesome-typescript-loader',
106 configFileName: 'tsconfig.webpack.json',
111 loader: 'angular2-template-loader'
114 exclude: [/\.(spec|e2e)\.ts$/]
118 * Json loader support for *.json files.
120 * See: https://github.com/webpack/json-loader
128 test: /\.(sass|scss)$/,
130 'css-to-string-loader',
132 loader: 'css-loader',
138 'resolve-url-loader',
140 loader: 'sass-loader',
146 loader: 'sass-resources-loader',
149 helpers
.root('src/sass/_variables.scss')
155 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
156 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
158 /* Raw loader support for *.html
159 * Returns file content as string
161 * See: https://github.com/webpack/raw-loader
167 helpers
.root('src/index.html'),
168 helpers
.root('src/standalone/videos/embed.html')
172 /* File loader for supporting images, for example, in CSS files.
175 test: /\.(jpg|png|gif)$/,
184 * Add additional plugins to the compiler.
186 * See: http://webpack.github.io/docs/configuration.html#plugins
190 path: helpers
.root('dist'),
191 filename: 'webpack-assets.json',
196 * Plugin: ForkCheckerPlugin
197 * Description: Do type checking in a separate process, so webpack don't need to wait.
199 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
204 * Plugin: CommonsChunkPlugin
205 * Description: Shares common code between the pages.
206 * It identifies common modules and put them into a commons chunk.
208 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
209 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
211 new CommonsChunkPlugin({
213 chunks: ['polyfills']
216 // This enables tree shaking of the vendor modules
217 new CommonsChunkPlugin({
220 minChunks: module
=> /node_modules\//.test(module
.resource
)
223 // Specify the correct order the scripts will be injected in
224 new CommonsChunkPlugin({
225 name: ['polyfills', 'vendor'].reverse()
229 * Plugin: ContextReplacementPlugin
230 * Description: Provides context to Angular's use of System.import
232 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
233 * See: https://github.com/angular/angular/issues/11580
235 new ContextReplacementPlugin(
237 * The (\\|\/) piece accounts for path separators in *nix and Windows
239 /(.+)?angular(\\|\/)core(.+)?/,
240 helpers
.root('src'), // location of your src
243 * Your Angular Async Route paths relative to this root directory
249 * Plugin: ScriptExtHtmlWebpackPlugin
250 * Description: Enhances html-webpack-plugin functionality
251 * with different deployment options for your scripts including:
253 * See: https://github.com/numical/script-ext-html-webpack-plugin
255 new ScriptExtHtmlWebpackPlugin({
256 sync: [ /polyfill|vendor/ ],
257 defaultAttribute: 'async',
258 preload: [/polyfill|vendor|main/],
263 * Plugin: HtmlWebpackPlugin
264 * Description: Simplifies creation of HTML files to serve your webpack bundles.
265 * This is especially useful for webpack bundles that include a hash in the filename
266 * which changes every compilation.
268 * See: https://github.com/ampedandwired/html-webpack-plugin
270 new HtmlWebpackPlugin({
271 template: 'src/index.html',
272 title: METADATA
.title
,
273 chunksSortMode: function (a
, b
) {
274 const entryPoints
= [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
275 return entryPoints
.indexOf(a
.names
[0]) - entryPoints
.indexOf(b
.names
[0])
281 new WebpackNotifierPlugin({ alwaysNotify: true }),
284 * Plugin LoaderOptionsPlugin (experimental)
286 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
288 new LoaderOptionsPlugin({
292 includePaths: [ helpers
.root('src/sass') ]
297 new ngcWebpack
.NgcWebpackPlugin({
299 tsConfig: helpers
.root('tsconfig.webpack.json')
302 new BundleAnalyzerPlugin({
303 // Can be `server`, `static` or `disabled`.
304 // In `server` mode analyzer will start HTTP server to show bundle report.
305 // In `static` mode single HTML file with bundle report will be generated.
306 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
307 analyzerMode: 'static',
308 // Path to bundle report file that will be generated in `static` mode.
309 // Relative to bundles output directory.
310 reportFilename: 'report.html',
311 // Automatically open report in default browser
313 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
314 generateStatsFile: true,
315 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
316 // Relative to bundles output directory.
317 statsFilename: 'stats.json',
318 // Options for `stats.toJson()` method.
319 // For example you can exclude sources of your modules from stats file with `source: false` option.
320 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
322 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
328 * Include polyfills or mocks for various node stuff
329 * Description: Node configuration
331 * See: https://webpack.github.io/docs/configuration.html#node
338 clearImmediate: false,