1 const webpack
= require('webpack')
2 const helpers
= require('./helpers')
8 const CopyWebpackPlugin
= require('copy-webpack-plugin')
9 const HtmlWebpackPlugin
= require('html-webpack-plugin')
10 const ForkCheckerPlugin
= require('awesome-typescript-loader').ForkCheckerPlugin
11 const AssetsPlugin
= require('assets-webpack-plugin')
12 const ContextReplacementPlugin
= require('webpack/lib/ContextReplacementPlugin')
13 const LoaderOptionsPlugin
= require('webpack/lib/LoaderOptionsPlugin')
14 const ScriptExtHtmlWebpackPlugin
= require('script-ext-html-webpack-plugin')
15 const WebpackNotifierPlugin
= require('webpack-notifier')
23 isDevServer: helpers
.isWebpackDevServer()
27 * Webpack configuration
29 * See: http://webpack.github.io/docs/configuration.html#cli
31 module
.exports = function (options
) {
32 var isProd
= options
.env
=== 'production'
37 * Cache generated modules and chunks to improve performance for multiple incremental builds.
38 * This is enabled by default in watch mode.
39 * You can pass false to disable it.
41 * See: http://webpack.github.io/docs/configuration.html#cache
46 * The entry point for the bundle
49 * See: http://webpack.github.io/docs/configuration.html#entry
52 'polyfills': './src/polyfills.ts',
53 'vendor': './src/vendor.ts',
54 'main': './src/main.ts'
58 * Options affecting the resolving of modules.
60 * See: http://webpack.github.io/docs/configuration.html#resolve
64 * An array of extensions that should be used to resolve modules.
66 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
68 extensions: [ '.ts', '.js', '.json', '.scss' ],
70 modules: [helpers
.root('src'), 'node_modules'],
73 'video.js': 'video.js/dist/alt/video.novtt'
78 * Options affecting the normal modules.
80 * See: http://webpack.github.io/docs/configuration.html#module
87 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
89 * See: https://github.com/s-panferov/awesome-typescript-loader
94 '@angularclass/hmr-loader?pretty=' + !isProd
+ '&prod=' + isProd
,
95 'awesome-typescript-loader',
96 'angular2-template-loader'
98 exclude: [/\.(spec|e2e)\.ts$/]
102 * Json loader support for *.json files.
104 * See: https://github.com/webpack/json-loader
108 loader: 'json-loader'
112 test: /\.(sass|scss)$/,
113 loaders: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url', 'sass-loader?sourceMap']
115 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url?limit=10000&minetype=application/font-woff' },
116 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file' },
118 /* Raw loader support for *.html
119 * Returns file content as string
121 * See: https://github.com/webpack/raw-loader
125 loader: 'raw-loader',
126 exclude: [ helpers
.root('src/index.html'), helpers
.root('src/standalone/videos/embed.html') ]
134 * Add additional plugins to the compiler.
136 * See: http://webpack.github.io/docs/configuration.html#plugins
140 path: helpers
.root('dist'),
141 filename: 'webpack-assets.json',
146 * Plugin: ForkCheckerPlugin
147 * Description: Do type checking in a separate process, so webpack don't need to wait.
149 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
151 new ForkCheckerPlugin(),
154 * Plugin: CommonsChunkPlugin
155 * Description: Shares common code between the pages.
156 * It identifies common modules and put them into a commons chunk.
158 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
159 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
161 new webpack
.optimize
.CommonsChunkPlugin({
162 name: [ 'polyfills', 'vendor' ].reverse()
166 * Plugin: ContextReplacementPlugin
167 * Description: Provides context to Angular's use of System.import
169 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
170 * See: https://github.com/angular/angular/issues/11580
172 new ContextReplacementPlugin(
173 // The (\\|\/) piece accounts for path separators in *nix and Windows
174 /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
175 helpers
.root('src') // location of your src
179 * Plugin: CopyWebpackPlugin
180 * Description: Copy files and directories in webpack.
182 * Copies project static assets.
184 * See: https://www.npmjs.com/package/copy-webpack-plugin
186 // Used by embed.html
187 new CopyWebpackPlugin([
193 from: 'node_modules/webtorrent/webtorrent.min.js',
194 to: 'assets/webtorrent'
197 from: 'node_modules/video.js/dist/video.min.js',
198 to: 'assets/video-js'
201 from: 'node_modules/video.js/dist/video-js.min.css',
202 to: 'assets/video-js'
205 from: 'node_modules/videojs-dock/dist/videojs-dock.min.js',
206 to: 'assets/video-js'
209 from: 'node_modules/videojs-dock/dist/videojs-dock.css',
210 to: 'assets/video-js'
213 from: 'src/standalone',
219 * Plugin: HtmlWebpackPlugin
220 * Description: Simplifies creation of HTML files to serve your webpack bundles.
221 * This is especially useful for webpack bundles that include a hash in the filename
222 * which changes every compilation.
224 * See: https://github.com/ampedandwired/html-webpack-plugin
226 new HtmlWebpackPlugin({
227 template: 'src/index.html',
228 title: METADATA
.title
,
229 chunksSortMode: 'dependency',
234 * Plugin: ScriptExtHtmlWebpackPlugin
235 * Description: Enhances html-webpack-plugin functionality
236 * with different deployment options for your scripts including:
238 * See: https://github.com/numical/script-ext-html-webpack-plugin
240 new ScriptExtHtmlWebpackPlugin({
241 sync: [ 'webtorrent.min.js' ],
242 defaultAttribute: 'defer'
245 new WebpackNotifierPlugin({ alwaysNotify: true }),
248 * Plugin LoaderOptionsPlugin (experimental)
250 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
252 new LoaderOptionsPlugin({
262 * Include polyfills or mocks for various node stuff
263 * Description: Node configuration
265 * See: https://webpack.github.io/docs/configuration.html#node
272 clearImmediate: false,