]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/config/webpack.common.js
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'
145 test: /\.(sass|scss)$/,
146 loaders: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url', 'sass-loader?sourceMap']
148 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url?limit=10000&minetype=application/font-woff' },
149 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file' },
151 /* Raw loader support for *.html
152 * Returns file content as string
154 * See: https://github.com/webpack/raw-loader
158 loader: 'raw-loader',
159 exclude: [ helpers
.root('src/index.html') ]
171 * Add additional plugins to the compiler.
173 * See: http://webpack.github.io/docs/configuration.html#plugins
177 path: helpers
.root('dist'),
178 filename: 'webpack-assets.json',
183 * Plugin: ForkCheckerPlugin
184 * Description: Do type checking in a separate process, so webpack don't need to wait.
186 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
188 new ForkCheckerPlugin(),
191 * Plugin: CommonsChunkPlugin
192 * Description: Shares common code between the pages.
193 * It identifies common modules and put them into a commons chunk.
195 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
196 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
198 new webpack
.optimize
.CommonsChunkPlugin({
199 name: [ 'polyfills', 'vendor' ].reverse()
203 * Plugin: ContextReplacementPlugin
204 * Description: Provides context to Angular's use of System.import
206 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
207 * See: https://github.com/angular/angular/issues/11580
209 new ContextReplacementPlugin(
210 // The (\\|\/) piece accounts for path separators in *nix and Windows
211 /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
212 helpers
.root('src') // location of your src
216 * Plugin: CopyWebpackPlugin
217 * Description: Copy files and directories in webpack.
219 * Copies project static assets.
221 * See: https://www.npmjs.com/package/copy-webpack-plugin
223 new CopyWebpackPlugin([
229 from: 'node_modules/webtorrent/webtorrent.min.js',
230 to: 'assets/webtorrent'
235 * Plugin: HtmlWebpackPlugin
236 * Description: Simplifies creation of HTML files to serve your webpack bundles.
237 * This is especially useful for webpack bundles that include a hash in the filename
238 * which changes every compilation.
240 * See: https://github.com/ampedandwired/html-webpack-plugin
242 new HtmlWebpackPlugin({
243 template: 'src/index.html',
244 chunksSortMode: 'dependency'
247 new WebpackNotifierPlugin({ alwaysNotify: true })
251 * Include polyfills or mocks for various node stuff
252 * Description: Node configuration
254 * See: https://webpack.github.io/docs/configuration.html#node
262 clearImmediate: false,