]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/config/webpack.common.js
2ce44b6c7e20de7567e53865d929f7f6676a6631
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 WebpackNotifierPlugin
= require('webpack-notifier')
20 isDevServer: helpers
.isWebpackDevServer()
24 * Webpack configuration
26 * See: http://webpack.github.io/docs/configuration.html#cli
28 module
.exports = function (options
) {
29 var isProd
= options
.env
=== 'production'
33 * Static metadata for index.html
35 * See: (custom attribute)
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.ts',
56 'vendor': './src/vendor.ts',
57 'main': './src/main.ts'
61 * Options affecting the resolving of modules.
63 * See: http://webpack.github.io/docs/configuration.html#resolve
67 * An array of extensions that should be used to resolve modules.
69 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
71 extensions: [ '', '.ts', '.js', '.scss' ],
73 // Make sure root is src
74 root: helpers
.root('src'),
76 // remove other default values
77 modulesDirectories: [ 'node_modules' ]
81 publicPath: '/client/'
85 * Options affecting the normal modules.
87 * See: http://webpack.github.io/docs/configuration.html#module
91 * An array of applied pre and post loaders.
93 * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
98 loader: 'string-replace-loader',
100 search: '(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import\\((.+)\\)',
101 replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
104 include: [helpers
.root('src')]
109 * An array of automatically applied loaders.
111 * IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
112 * This means they are not resolved relative to the configuration file.
114 * See: http://webpack.github.io/docs/configuration.html#module-loaders
119 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
121 * See: https://github.com/s-panferov/awesome-typescript-loader
126 '@angularclass/hmr-loader?pretty=' + !isProd
+ '&prod=' + isProd
,
127 'awesome-typescript-loader',
128 'angular2-template-loader'
130 exclude: [/\.(spec|e2e)\.ts$/]
134 * Json loader support for *.json files.
136 * See: https://github.com/webpack/json-loader
140 loader: 'json-loader'
145 exclude: /node_modules/,
146 loaders: [ 'raw-loader', 'sass-loader' ]
150 test: /\.(woff2?|ttf|eot|svg)$/,
151 loader: 'url?limit=10000&name=assets/fonts/[hash].[ext]'
154 /* Raw loader support for *.html
155 * Returns file content as string
157 * See: https://github.com/webpack/raw-loader
161 loader: 'raw-loader',
162 exclude: [ helpers
.root('src/index.html') ]
174 * Add additional plugins to the compiler.
176 * See: http://webpack.github.io/docs/configuration.html#plugins
180 path: helpers
.root('dist'),
181 filename: 'webpack-assets.json',
186 * Plugin: ForkCheckerPlugin
187 * Description: Do type checking in a separate process, so webpack don't need to wait.
189 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
191 new ForkCheckerPlugin(),
194 * Plugin: CommonsChunkPlugin
195 * Description: Shares common code between the pages.
196 * It identifies common modules and put them into a commons chunk.
198 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
199 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
201 new webpack
.optimize
.CommonsChunkPlugin({
202 name: [ 'polyfills', 'vendor' ].reverse()
206 * Plugin: CopyWebpackPlugin
207 * Description: Copy files and directories in webpack.
209 * Copies project static assets.
211 * See: https://www.npmjs.com/package/copy-webpack-plugin
213 new CopyWebpackPlugin([
219 from: 'node_modules/webtorrent/webtorrent.min.js',
220 to: 'assets/webtorrent'
225 * Plugin: HtmlWebpackPlugin
226 * Description: Simplifies creation of HTML files to serve your webpack bundles.
227 * This is especially useful for webpack bundles that include a hash in the filename
228 * which changes every compilation.
230 * See: https://github.com/ampedandwired/html-webpack-plugin
232 new HtmlWebpackPlugin({
233 template: 'src/index.html',
234 chunksSortMode: 'dependency'
237 new WebpackNotifierPlugin({ alwaysNotify: true })
241 * Include polyfills or mocks for various node stuff
242 * Description: Node configuration
244 * See: https://webpack.github.io/docs/configuration.html#node
252 clearImmediate: false,