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')
16 const CopyWebpackPlugin
= require('copy-webpack-plugin')
18 const WebpackNotifierPlugin
= require('webpack-notifier')
20 const HMR
= helpers
.hasProcessFlag('hot')
21 const AOT
= process
.env
.BUILD_AOT
|| helpers
.hasNpmFlag('aot')
25 isDevServer: helpers
.isWebpackDevServer(),
31 * Webpack configuration
33 * See: http://webpack.github.io/docs/configuration.html#cli
35 module
.exports = function (options
) {
36 const isProd
= options
.env
=== 'production'
42 * Cache generated modules and chunks to improve performance for multiple incremental builds.
43 * This is enabled by default in watch mode.
44 * You can pass false to disable it.
46 * See: http://webpack.github.io/docs/configuration.html#cache
51 * The entry point for the bundle
54 * See: http://webpack.github.io/docs/configuration.html#entry
57 'polyfills': './src/polyfills.browser.ts',
59 ? './src/main.browser.aot.ts'
60 : './src/main.browser.ts'
64 * Options affecting the resolving of modules.
66 * See: http://webpack.github.io/docs/configuration.html#resolve
70 * An array of extensions that should be used to resolve modules.
72 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
74 extensions: [ '.ts', '.js', '.json', '.scss' ],
76 modules: [ helpers
.root('src'), helpers
.root('node_modules') ]
80 * Options affecting the normal modules.
82 * See: http://webpack.github.io/docs/configuration.html#module
89 * Typescript loader support for .ts and Angular async routes via .async.ts
91 * See: https://github.com/s-panferov/awesome-typescript-loader
97 loader: 'ng-router-loader',
99 loader: 'async-import',
105 loader: 'awesome-typescript-loader',
107 configFileName: 'tsconfig.webpack.json',
112 loader: 'angular2-template-loader'
115 exclude: [/\.(spec|e2e)\.ts$/]
119 * Json loader support for *.json files.
121 * See: https://github.com/webpack/json-loader
129 test: /\.(sass|scss)$/,
131 'css-to-string-loader',
133 loader: 'css-loader',
139 'resolve-url-loader',
141 loader: 'sass-loader',
147 loader: 'sass-resources-loader',
150 helpers
.root('src/sass/_variables.scss'),
151 helpers
.root('src/sass/_mixins.scss')
157 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
158 { test: /\.(otf|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000' },
160 /* Raw loader support for *.html
161 * Returns file content as string
163 * See: https://github.com/webpack/raw-loader
169 helpers
.root('src/index.html'),
170 helpers
.root('src/standalone/videos/embed.html')
174 /* File loader for supporting images, for example, in CSS files.
177 test: /\.(jpg|png|gif)$/,
186 * Add additional plugins to the compiler.
188 * See: http://webpack.github.io/docs/configuration.html#plugins
192 path: helpers
.root('dist'),
193 filename: 'webpack-assets.json',
198 * Plugin: ForkCheckerPlugin
199 * Description: Do type checking in a separate process, so webpack don't need to wait.
201 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
206 * Plugin: CommonsChunkPlugin
207 * Description: Shares common code between the pages.
208 * It identifies common modules and put them into a commons chunk.
210 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
211 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
213 new CommonsChunkPlugin({
215 chunks: ['polyfills']
218 // This enables tree shaking of the vendor modules
219 new CommonsChunkPlugin({
222 minChunks: module
=> {
223 return /node_modules\//.test(module
.resource
)
227 // Specify the correct order the scripts will be injected in
228 new CommonsChunkPlugin({
229 name: ['polyfills', 'vendor'].reverse()
233 * Plugin: ContextReplacementPlugin
234 * Description: Provides context to Angular's use of System.import
236 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
237 * See: https://github.com/angular/angular/issues/11580
239 new ContextReplacementPlugin(
241 * The (\\|\/) piece accounts for path separators in *nix and Windows
243 /(.+)?angular(\\|\/)core(.+)?/,
244 helpers
.root('src'), // location of your src
247 * Your Angular Async Route paths relative to this root directory
253 * Plugin: HtmlWebpackPlugin
254 * Description: Simplifies creation of HTML files to serve your webpack bundles.
255 * This is especially useful for webpack bundles that include a hash in the filename
256 * which changes every compilation.
258 * See: https://github.com/ampedandwired/html-webpack-plugin
260 new HtmlWebpackPlugin({
261 template: 'src/index.html',
262 title: METADATA
.title
,
263 chunksSortMode: function (a
, b
) {
264 const entryPoints
= [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
265 return entryPoints
.indexOf(a
.names
[0]) - entryPoints
.indexOf(b
.names
[0])
271 new CopyWebpackPlugin([
273 from: helpers
.root('src/assets/images/favicon.png'),
274 to: 'assets/images/favicon.png'
277 from: helpers
.root('src/assets/images/default-avatar.png'),
278 to: 'assets/images/default-avatar.png'
283 * Plugin: ScriptExtHtmlWebpackPlugin
284 * Description: Enhances html-webpack-plugin functionality
285 * with different deployment options for your scripts including:
287 * See: https://github.com/numical/script-ext-html-webpack-plugin
289 new ScriptExtHtmlWebpackPlugin({
290 sync: [ /polyfill|vendor/ ],
291 defaultAttribute: 'async',
292 preload: [/polyfill|vendor|main/],
296 new WebpackNotifierPlugin({ alwaysNotify: true }),
299 * Plugin LoaderOptionsPlugin (experimental)
301 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
303 new LoaderOptionsPlugin({
308 includePaths: [ helpers
.root('src/sass') ]
313 new ngcWebpack
.NgcWebpackPlugin({
315 tsConfig: helpers
.root('tsconfig.webpack.json')
318 new InlineManifestWebpackPlugin()
322 * Include polyfills or mocks for various node stuff
323 * Description: Node configuration
325 * See: https://webpack.github.io/docs/configuration.html#node
332 clearImmediate: false,