1 const helpers
= require('./helpers')
7 const AssetsPlugin
= require('assets-webpack-plugin')
8 const ContextReplacementPlugin
= require('webpack/lib/ContextReplacementPlugin')
9 const CommonsChunkPlugin
= require('webpack/lib/optimize/CommonsChunkPlugin')
10 const CheckerPlugin
= require('awesome-typescript-loader').CheckerPlugin
11 const HtmlWebpackPlugin
= require('html-webpack-plugin')
12 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
13 const ScriptExtHtmlWebpackPlugin
= require('script-ext-html-webpack-plugin')
14 const InlineManifestWebpackPlugin
= require('inline-manifest-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'),
150 helpers
.root('src/sass/_mixins.scss')
156 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
157 { test: /\.(otf|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000' },
159 /* Raw loader support for *.html
160 * Returns file content as string
162 * See: https://github.com/webpack/raw-loader
168 helpers
.root('src/index.html'),
169 helpers
.root('src/standalone/videos/embed.html')
173 /* File loader for supporting images, for example, in CSS files.
176 test: /\.(jpg|png|gif)$/,
185 * Add additional plugins to the compiler.
187 * See: http://webpack.github.io/docs/configuration.html#plugins
191 path: helpers
.root('dist'),
192 filename: 'webpack-assets.json',
197 * Plugin: ForkCheckerPlugin
198 * Description: Do type checking in a separate process, so webpack don't need to wait.
200 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
205 * Plugin: CommonsChunkPlugin
206 * Description: Shares common code between the pages.
207 * It identifies common modules and put them into a commons chunk.
209 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
210 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
212 new CommonsChunkPlugin({
214 chunks: ['polyfills']
217 // This enables tree shaking of the vendor modules
218 new CommonsChunkPlugin({
221 minChunks: module
=> {
222 return /node_modules\//.test(module
.resource
)
226 // Specify the correct order the scripts will be injected in
227 new CommonsChunkPlugin({
228 name: ['polyfills', 'vendor'].reverse()
232 * Plugin: ContextReplacementPlugin
233 * Description: Provides context to Angular's use of System.import
235 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
236 * See: https://github.com/angular/angular/issues/11580
238 new ContextReplacementPlugin(
240 * The (\\|\/) piece accounts for path separators in *nix and Windows
242 /(.+)?angular(\\|\/)core(.+)?/,
243 helpers
.root('src'), // location of your src
246 * Your Angular Async Route paths relative to this root directory
252 * Plugin: HtmlWebpackPlugin
253 * Description: Simplifies creation of HTML files to serve your webpack bundles.
254 * This is especially useful for webpack bundles that include a hash in the filename
255 * which changes every compilation.
257 * See: https://github.com/ampedandwired/html-webpack-plugin
259 new HtmlWebpackPlugin({
260 template: 'src/index.html',
261 title: METADATA
.title
,
262 chunksSortMode: function (a
, b
) {
263 const entryPoints
= [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
264 return entryPoints
.indexOf(a
.names
[0]) - entryPoints
.indexOf(b
.names
[0])
271 * Plugin: ScriptExtHtmlWebpackPlugin
272 * Description: Enhances html-webpack-plugin functionality
273 * with different deployment options for your scripts including:
275 * See: https://github.com/numical/script-ext-html-webpack-plugin
277 new ScriptExtHtmlWebpackPlugin({
278 sync: [ /polyfill|vendor/ ],
279 defaultAttribute: 'async',
280 preload: [/polyfill|vendor|main/],
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 InlineManifestWebpackPlugin()
309 * Include polyfills or mocks for various node stuff
310 * Description: Node configuration
312 * See: https://webpack.github.io/docs/configuration.html#node
319 clearImmediate: false,