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')
25 isDevServer: helpers
.isWebpackDevServer()
29 * Webpack configuration
31 * See: http://webpack.github.io/docs/configuration.html#cli
33 module
.exports = function (options
) {
34 const isProd
= options
.env
=== 'production'
40 * Cache generated modules and chunks to improve performance for multiple incremental builds.
41 * This is enabled by default in watch mode.
42 * You can pass false to disable it.
44 * See: http://webpack.github.io/docs/configuration.html#cache
49 * The entry point for the bundle
52 * See: http://webpack.github.io/docs/configuration.html#entry
55 'polyfills': './src/polyfills.browser.ts',
57 ? './src/main.browser.aot.ts'
58 : './src/main.browser.ts'
62 * Options affecting the resolving of modules.
64 * See: http://webpack.github.io/docs/configuration.html#resolve
68 * An array of extensions that should be used to resolve modules.
70 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
72 extensions: [ '.ts', '.js', '.json', '.scss' ],
74 modules: [ helpers
.root('src'), helpers
.root('node_modules') ]
78 * Options affecting the normal modules.
80 * See: http://webpack.github.io/docs/configuration.html#module
87 * Typescript loader support for .ts and Angular async routes via .async.ts
89 * See: https://github.com/s-panferov/awesome-typescript-loader
95 loader: '@angularclass/hmr-loader',
102 loader: 'ng-router-loader',
104 loader: 'async-import',
110 loader: 'awesome-typescript-loader',
112 configFileName: 'tsconfig.webpack.json',
117 loader: 'angular2-template-loader'
120 exclude: [/\.(spec|e2e)\.ts$/]
124 * Json loader support for *.json files.
126 * See: https://github.com/webpack/json-loader
134 test: /\.(sass|scss)$/,
136 'css-to-string-loader',
138 loader: 'css-loader',
144 'resolve-url-loader',
146 loader: 'sass-loader',
152 loader: 'sass-resources-loader',
155 helpers
.root('src/sass/_variables.scss')
161 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
162 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
164 /* Raw loader support for *.html
165 * Returns file content as string
167 * See: https://github.com/webpack/raw-loader
173 helpers
.root('src/index.html'),
174 helpers
.root('src/standalone/videos/embed.html')
178 /* File loader for supporting images, for example, in CSS files.
181 test: /\.(jpg|png|gif)$/,
190 * Add additional plugins to the compiler.
192 * See: http://webpack.github.io/docs/configuration.html#plugins
196 path: helpers
.root('dist'),
197 filename: 'webpack-assets.json',
202 * Plugin: ForkCheckerPlugin
203 * Description: Do type checking in a separate process, so webpack don't need to wait.
205 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
210 * Plugin: CommonsChunkPlugin
211 * Description: Shares common code between the pages.
212 * It identifies common modules and put them into a commons chunk.
214 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
215 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
217 new CommonsChunkPlugin({
219 chunks: ['polyfills']
222 // This enables tree shaking of the vendor modules
223 new CommonsChunkPlugin({
226 minChunks: module
=> /node_modules\//.test(module
.resource
)
229 // Specify the correct order the scripts will be injected in
230 new CommonsChunkPlugin({
231 name: ['polyfills', 'vendor'].reverse()
235 * Plugin: ContextReplacementPlugin
236 * Description: Provides context to Angular's use of System.import
238 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
239 * See: https://github.com/angular/angular/issues/11580
241 new ContextReplacementPlugin(
243 * The (\\|\/) piece accounts for path separators in *nix and Windows
245 /angular(\\|\/)core(\\|\/)@angular/,
246 helpers
.root('src'), // location of your src
249 * Your Angular Async Route paths relative to this root directory
255 * Plugin: ScriptExtHtmlWebpackPlugin
256 * Description: Enhances html-webpack-plugin functionality
257 * with different deployment options for your scripts including:
259 * See: https://github.com/numical/script-ext-html-webpack-plugin
261 new ScriptExtHtmlWebpackPlugin({
262 sync: [ /polyfill|vendor/ ],
263 defaultAttribute: 'async',
264 preload: [/polyfill|vendor|main/],
269 * Plugin: HtmlWebpackPlugin
270 * Description: Simplifies creation of HTML files to serve your webpack bundles.
271 * This is especially useful for webpack bundles that include a hash in the filename
272 * which changes every compilation.
274 * See: https://github.com/ampedandwired/html-webpack-plugin
276 new HtmlWebpackPlugin({
277 template: 'src/index.html',
278 title: METADATA
.title
,
279 chunksSortMode: 'dependency',
284 new WebpackNotifierPlugin({ alwaysNotify: true }),
287 * Plugin LoaderOptionsPlugin (experimental)
289 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
291 new LoaderOptionsPlugin({
295 includePaths: [ helpers
.root('src/sass') ]
300 new ngcWebpack
.NgcWebpackPlugin({
302 tsConfig: helpers
.root('tsconfig.webpack.json')
305 new BundleAnalyzerPlugin({
306 // Can be `server`, `static` or `disabled`.
307 // In `server` mode analyzer will start HTTP server to show bundle report.
308 // In `static` mode single HTML file with bundle report will be generated.
309 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
310 analyzerMode: 'static',
311 // Path to bundle report file that will be generated in `static` mode.
312 // Relative to bundles output directory.
313 reportFilename: 'report.html',
314 // Automatically open report in default browser
316 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
317 generateStatsFile: true,
318 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
319 // Relative to bundles output directory.
320 statsFilename: 'stats.json',
321 // Options for `stats.toJson()` method.
322 // For example you can exclude sources of your modules from stats file with `source: false` option.
323 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
325 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
331 * Include polyfills or mocks for various node stuff
332 * Description: Node configuration
334 * See: https://webpack.github.io/docs/configuration.html#node
341 clearImmediate: false,