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 CopyWebpackPlugin
= require('copy-webpack-plugin')
12 const CheckerPlugin
= require('awesome-typescript-loader').CheckerPlugin
13 const HtmlWebpackPlugin
= require('html-webpack-plugin')
14 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
15 const ScriptExtHtmlWebpackPlugin
= require('script-ext-html-webpack-plugin')
16 const ngcWebpack
= require('ngc-webpack')
18 const WebpackNotifierPlugin
= require('webpack-notifier')
26 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 2 async routes via .async.ts
90 * See: https://github.com/s-panferov/awesome-typescript-loader
95 '@angularclass/hmr-loader?pretty=' + !isProd
+ '&prod=' + isProd
,
96 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
97 'angular2-template-loader',
99 loader: 'ng-router-loader',
101 loader: 'async-system',
107 exclude: [/\.(spec|e2e)\.ts$/]
111 * Json loader support for *.json files.
113 * See: https://github.com/webpack/json-loader
117 loader: 'json-loader'
121 test: /\.(sass|scss)$/,
123 'css-to-string-loader',
124 'css-loader?sourceMap',
125 'resolve-url-loader',
127 loader: 'sass-loader',
133 loader: 'sass-resources-loader',
136 helpers
.root('src/sass/_variables.scss')
142 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
143 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
145 /* Raw loader support for *.html
146 * Returns file content as string
148 * See: https://github.com/webpack/raw-loader
152 loader: 'raw-loader',
154 helpers
.root('src/index.html'),
155 helpers
.root('src/standalone/videos/embed.html')
164 * Add additional plugins to the compiler.
166 * See: http://webpack.github.io/docs/configuration.html#plugins
170 path: helpers
.root('dist'),
171 filename: 'webpack-assets.json',
176 * Plugin: ForkCheckerPlugin
177 * Description: Do type checking in a separate process, so webpack don't need to wait.
179 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
184 * Plugin: CommonsChunkPlugin
185 * Description: Shares common code between the pages.
186 * It identifies common modules and put them into a commons chunk.
188 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
189 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
191 new CommonsChunkPlugin({
193 chunks: ['polyfills']
196 // This enables tree shaking of the vendor modules
197 new CommonsChunkPlugin({
200 minChunks: module
=> /node_modules\//.test(module
.resource
)
203 // Specify the correct order the scripts will be injected in
204 new CommonsChunkPlugin({
205 name: ['polyfills', 'vendor'].reverse()
209 * Plugin: ContextReplacementPlugin
210 * Description: Provides context to Angular's use of System.import
212 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
213 * See: https://github.com/angular/angular/issues/11580
215 new ContextReplacementPlugin(
216 // The (\\|\/) piece accounts for path separators in *nix and Windows
217 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
218 helpers
.root('src'), // location of your src
220 // your Angular Async Route paths relative to this root directory
225 * Plugin: CopyWebpackPlugin
226 * Description: Copy files and directories in webpack.
228 * Copies project static assets.
230 * See: https://www.npmjs.com/package/copy-webpack-plugin
232 // Used by embed.html
233 new CopyWebpackPlugin([
239 from: 'node_modules/webtorrent/webtorrent.min.js',
240 to: 'assets/webtorrent'
243 from: 'src/standalone',
249 * Plugin: HtmlWebpackPlugin
250 * Description: Simplifies creation of HTML files to serve your webpack bundles.
251 * This is especially useful for webpack bundles that include a hash in the filename
252 * which changes every compilation.
254 * See: https://github.com/ampedandwired/html-webpack-plugin
256 new HtmlWebpackPlugin({
257 template: 'src/index.html',
258 title: METADATA
.title
,
259 chunksSortMode: 'dependency',
264 * Plugin: ScriptExtHtmlWebpackPlugin
265 * Description: Enhances html-webpack-plugin functionality
266 * with different deployment options for your scripts including:
268 * See: https://github.com/numical/script-ext-html-webpack-plugin
270 new ScriptExtHtmlWebpackPlugin({
271 sync: [ 'webtorrent.min.js' ],
272 defaultAttribute: 'defer'
275 new WebpackNotifierPlugin({ alwaysNotify: true }),
278 * Plugin LoaderOptionsPlugin (experimental)
280 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
282 new LoaderOptionsPlugin({
286 includePaths: [ helpers
.root('src/sass') ]
291 new ngcWebpack
.NgcWebpackPlugin({
293 tsConfig: helpers
.root('tsconfig.webpack.json'),
294 resourceOverride: helpers
.root('config/resource-override.js')
297 new BundleAnalyzerPlugin({
298 // Can be `server`, `static` or `disabled`.
299 // In `server` mode analyzer will start HTTP server to show bundle report.
300 // In `static` mode single HTML file with bundle report will be generated.
301 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
302 analyzerMode: 'static',
303 // Path to bundle report file that will be generated in `static` mode.
304 // Relative to bundles output directory.
305 reportFilename: 'report.html',
306 // Automatically open report in default browser
308 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
309 generateStatsFile: true,
310 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
311 // Relative to bundles output directory.
312 statsFilename: 'stats.json',
313 // Options for `stats.toJson()` method.
314 // For example you can exclude sources of your modules from stats file with `source: false` option.
315 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
317 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
323 * Include polyfills or mocks for various node stuff
324 * Description: Node configuration
326 * See: https://webpack.github.io/docs/configuration.html#node
333 clearImmediate: false,