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')
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
=> {
221 return /node_modules\//.test(module
.resource
)
225 // Specify the correct order the scripts will be injected in
226 new CommonsChunkPlugin({
227 name: ['polyfills', 'vendor'].reverse()
231 * Plugin: ContextReplacementPlugin
232 * Description: Provides context to Angular's use of System.import
234 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
235 * See: https://github.com/angular/angular/issues/11580
237 new ContextReplacementPlugin(
239 * The (\\|\/) piece accounts for path separators in *nix and Windows
241 /(.+)?angular(\\|\/)core(.+)?/,
242 helpers
.root('src'), // location of your src
245 * Your Angular Async Route paths relative to this root directory
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: function (a
, b
) {
262 const entryPoints
= [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
263 return entryPoints
.indexOf(a
.names
[0]) - entryPoints
.indexOf(b
.names
[0])
270 * Plugin: ScriptExtHtmlWebpackPlugin
271 * Description: Enhances html-webpack-plugin functionality
272 * with different deployment options for your scripts including:
274 * See: https://github.com/numical/script-ext-html-webpack-plugin
276 new ScriptExtHtmlWebpackPlugin({
277 sync: [ /polyfill|vendor/ ],
278 defaultAttribute: 'async',
279 preload: [/polyfill|vendor|main/],
283 new WebpackNotifierPlugin({ alwaysNotify: true }),
286 * Plugin LoaderOptionsPlugin (experimental)
288 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
290 new LoaderOptionsPlugin({
294 includePaths: [ helpers
.root('src/sass') ]
299 new ngcWebpack
.NgcWebpackPlugin({
301 tsConfig: helpers
.root('tsconfig.webpack.json')
304 new InlineManifestWebpackPlugin()
308 * Include polyfills or mocks for various node stuff
309 * Description: Node configuration
311 * See: https://webpack.github.io/docs/configuration.html#node
318 clearImmediate: false,