]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/config/webpack.common.js
88a3639d2cbf52d01d45953bcdc28a5a71637d61
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 WebpackNotifierPlugin
= require('webpack-notifier')
21 isDevServer: helpers
.isWebpackDevServer()
25 * Webpack configuration
27 * See: http://webpack.github.io/docs/configuration.html#cli
29 module
.exports = function (options
) {
30 var isProd
= options
.env
=== 'production'
34 * Static metadata for index.html
36 * See: (custom attribute)
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.ts',
57 'vendor': './src/vendor.ts',
58 'main': './src/main.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', '.scss' ],
74 // Make sure root is src
75 root: helpers
.root('src'),
77 // remove other default values
78 modulesDirectories: [ 'node_modules' ]
82 publicPath: '/client/'
86 * Options affecting the normal modules.
88 * See: http://webpack.github.io/docs/configuration.html#module
92 * An array of applied pre and post loaders.
94 * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
99 loader: 'string-replace-loader',
101 search: '(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import\\((.+)\\)',
102 replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
105 include: [helpers
.root('src')]
110 * An array of automatically applied loaders.
112 * IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
113 * This means they are not resolved relative to the configuration file.
115 * See: http://webpack.github.io/docs/configuration.html#module-loaders
120 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
122 * See: https://github.com/s-panferov/awesome-typescript-loader
127 '@angularclass/hmr-loader?pretty=' + !isProd
+ '&prod=' + isProd
,
128 'awesome-typescript-loader',
129 'angular2-template-loader'
131 exclude: [/\.(spec|e2e)\.ts$/]
135 * Json loader support for *.json files.
137 * See: https://github.com/webpack/json-loader
141 loader: 'json-loader'
146 exclude: /node_modules/,
147 loaders: [ 'raw-loader', 'sass-loader' ]
151 test: /\.(woff2?|ttf|eot|svg)$/,
152 loader: 'url?limit=10000&name=assets/fonts/[hash].[ext]'
155 /* Raw loader support for *.html
156 * Returns file content as string
158 * See: https://github.com/webpack/raw-loader
162 loader: 'raw-loader',
163 exclude: [ helpers
.root('src/index.html') ]
175 * Add additional plugins to the compiler.
177 * See: http://webpack.github.io/docs/configuration.html#plugins
181 path: helpers
.root('dist'),
182 filename: 'webpack-assets.json',
187 * Plugin: ForkCheckerPlugin
188 * Description: Do type checking in a separate process, so webpack don't need to wait.
190 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
192 new ForkCheckerPlugin(),
195 * Plugin: CommonsChunkPlugin
196 * Description: Shares common code between the pages.
197 * It identifies common modules and put them into a commons chunk.
199 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
200 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
202 new webpack
.optimize
.CommonsChunkPlugin({
203 name: [ 'polyfills', 'vendor' ].reverse()
207 * Plugin: ContextReplacementPlugin
208 * Description: Provides context to Angular's use of System.import
210 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
211 * See: https://github.com/angular/angular/issues/11580
213 new ContextReplacementPlugin(
214 // The (\\|\/) piece accounts for path separators in *nix and Windows
215 /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
216 helpers
.root('src') // location of your src
220 * Plugin: CopyWebpackPlugin
221 * Description: Copy files and directories in webpack.
223 * Copies project static assets.
225 * See: https://www.npmjs.com/package/copy-webpack-plugin
227 new CopyWebpackPlugin([
233 from: 'node_modules/webtorrent/webtorrent.min.js',
234 to: 'assets/webtorrent'
239 * Plugin: HtmlWebpackPlugin
240 * Description: Simplifies creation of HTML files to serve your webpack bundles.
241 * This is especially useful for webpack bundles that include a hash in the filename
242 * which changes every compilation.
244 * See: https://github.com/ampedandwired/html-webpack-plugin
246 new HtmlWebpackPlugin({
247 template: 'src/index.html',
248 chunksSortMode: 'dependency'
251 new WebpackNotifierPlugin({ alwaysNotify: true })
255 * Include polyfills or mocks for various node stuff
256 * Description: Node configuration
258 * See: https://webpack.github.io/docs/configuration.html#node
266 clearImmediate: false,