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 ngcWebpack
= require('ngc-webpack')
16 const WebpackNotifierPlugin
= require('webpack-notifier')
18 const HMR
= helpers
.hasProcessFlag('hot')
19 const AOT
= process
.env
.BUILD_AOT
|| helpers
.hasNpmFlag('aot')
23 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: 'ng-router-loader',
97 loader: 'async-import',
103 loader: 'awesome-typescript-loader',
105 configFileName: 'tsconfig.webpack.json',
110 loader: 'angular2-template-loader'
113 exclude: [/\.(spec|e2e)\.ts$/]
117 * Json loader support for *.json files.
119 * See: https://github.com/webpack/json-loader
127 test: /\.(sass|scss)$/,
129 'css-to-string-loader',
131 loader: 'css-loader',
137 'resolve-url-loader',
139 loader: 'sass-loader',
145 loader: 'sass-resources-loader',
148 helpers
.root('src/sass/_variables.scss')
154 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
155 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
157 /* Raw loader support for *.html
158 * Returns file content as string
160 * See: https://github.com/webpack/raw-loader
166 helpers
.root('src/index.html'),
167 helpers
.root('src/standalone/videos/embed.html')
171 /* File loader for supporting images, for example, in CSS files.
174 test: /\.(jpg|png|gif)$/,
183 * Add additional plugins to the compiler.
185 * See: http://webpack.github.io/docs/configuration.html#plugins
189 path: helpers
.root('dist'),
190 filename: 'webpack-assets.json',
195 * Plugin: ForkCheckerPlugin
196 * Description: Do type checking in a separate process, so webpack don't need to wait.
198 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
203 * Plugin: CommonsChunkPlugin
204 * Description: Shares common code between the pages.
205 * It identifies common modules and put them into a commons chunk.
207 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
208 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
210 new CommonsChunkPlugin({
212 chunks: ['polyfills']
215 // This enables tree shaking of the vendor modules
216 new CommonsChunkPlugin({
219 minChunks: module
=> /node_modules\//.test(module
.resource
)
222 // Specify the correct order the scripts will be injected in
223 new CommonsChunkPlugin({
224 name: ['polyfills', 'vendor'].reverse()
228 * Plugin: ContextReplacementPlugin
229 * Description: Provides context to Angular's use of System.import
231 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
232 * See: https://github.com/angular/angular/issues/11580
234 new ContextReplacementPlugin(
236 * The (\\|\/) piece accounts for path separators in *nix and Windows
238 /(.+)?angular(\\|\/)core(.+)?/,
239 helpers
.root('src'), // location of your src
242 * Your Angular Async Route paths relative to this root directory
248 * Plugin: ScriptExtHtmlWebpackPlugin
249 * Description: Enhances html-webpack-plugin functionality
250 * with different deployment options for your scripts including:
252 * See: https://github.com/numical/script-ext-html-webpack-plugin
254 new ScriptExtHtmlWebpackPlugin({
255 sync: [ /polyfill|vendor/ ],
256 defaultAttribute: 'async',
257 preload: [/polyfill|vendor|main/],
262 * Plugin: HtmlWebpackPlugin
263 * Description: Simplifies creation of HTML files to serve your webpack bundles.
264 * This is especially useful for webpack bundles that include a hash in the filename
265 * which changes every compilation.
267 * See: https://github.com/ampedandwired/html-webpack-plugin
269 new HtmlWebpackPlugin({
270 template: 'src/index.html',
271 title: METADATA
.title
,
272 chunksSortMode: function (a
, b
) {
273 const entryPoints
= [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
274 return entryPoints
.indexOf(a
.names
[0]) - entryPoints
.indexOf(b
.names
[0])
280 new WebpackNotifierPlugin({ alwaysNotify: true }),
283 * Plugin LoaderOptionsPlugin (experimental)
285 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
287 new LoaderOptionsPlugin({
291 includePaths: [ helpers
.root('src/sass') ]
296 new ngcWebpack
.NgcWebpackPlugin({
298 tsConfig: helpers
.root('tsconfig.webpack.json')
303 * Include polyfills or mocks for various node stuff
304 * Description: Node configuration
306 * See: https://webpack.github.io/docs/configuration.html#node
313 clearImmediate: false,