]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.common.js
Client: fix handle refresh token
[github/Chocobozzz/PeerTube.git] / client / config / webpack.common.js
CommitLineData
4a6995be
C
1const webpack = require('webpack')
2const helpers = require('./helpers')
3
4/*
5 * Webpack Plugins
6 */
7
ab32b0fc 8const CopyWebpackPlugin = require('copy-webpack-plugin')
4a6995be
C
9const HtmlWebpackPlugin = require('html-webpack-plugin')
10const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin
2e92c10b 11const AssetsPlugin = require('assets-webpack-plugin')
d268c551 12const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
66698b83 13const WebpackNotifierPlugin = require('webpack-notifier')
4a6995be
C
14
15/*
16 * Webpack Constants
17 */
18const METADATA = {
19 title: 'PeerTube',
ab32b0fc
C
20 baseUrl: '/',
21 isDevServer: helpers.isWebpackDevServer()
4a6995be
C
22}
23
24/*
25 * Webpack configuration
26 *
27 * See: http://webpack.github.io/docs/configuration.html#cli
28 */
2e92c10b
C
29module.exports = function (options) {
30 var isProd = options.env === 'production'
31
32 return {
4a6995be 33 /*
2e92c10b 34 * Static metadata for index.html
4a6995be 35 *
2e92c10b 36 * See: (custom attribute)
4a6995be 37 */
2e92c10b 38 metadata: METADATA,
4a6995be 39
2e92c10b
C
40 /*
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.
44 *
45 * See: http://webpack.github.io/docs/configuration.html#cache
46 */
47 // cache: false,
4a6995be 48
2e92c10b
C
49 /*
50 * The entry point for the bundle
51 * Our Angular.js app
52 *
53 * See: http://webpack.github.io/docs/configuration.html#entry
54 */
55 entry: {
56 'polyfills': './src/polyfills.ts',
57 'vendor': './src/vendor.ts',
58 'main': './src/main.ts'
59 },
b20b5fed 60
4a6995be 61 /*
2e92c10b 62 * Options affecting the resolving of modules.
4a6995be 63 *
2e92c10b 64 * See: http://webpack.github.io/docs/configuration.html#resolve
4a6995be 65 */
2e92c10b
C
66 resolve: {
67 /*
68 * An array of extensions that should be used to resolve modules.
69 *
70 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
71 */
72 extensions: [ '', '.ts', '.js', '.scss' ],
4a6995be 73
2e92c10b
C
74 // Make sure root is src
75 root: helpers.root('src'),
76
77 // remove other default values
78 modulesDirectories: [ 'node_modules' ]
79 },
80
81 output: {
82 publicPath: '/client/'
83 },
4a6995be
C
84
85 /*
2e92c10b 86 * Options affecting the normal modules.
4a6995be 87 *
2e92c10b 88 * See: http://webpack.github.io/docs/configuration.html#module
4a6995be 89 */
2e92c10b 90 module: {
4a6995be 91 /*
2e92c10b 92 * An array of applied pre and post loaders.
4a6995be 93 *
2e92c10b 94 * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
4a6995be 95 */
2e92c10b
C
96 preLoaders: [
97 {
98 test: /\.ts$/,
99 loader: 'string-replace-loader',
100 query: {
101 search: '(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import\\((.+)\\)',
102 replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
103 flags: 'g'
104 },
105 include: [helpers.root('src')]
106 }
107 ],
4a6995be
C
108
109 /*
2e92c10b 110 * An array of automatically applied loaders.
4a6995be 111 *
2e92c10b
C
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.
4a6995be 114 *
2e92c10b 115 * See: http://webpack.github.io/docs/configuration.html#module-loaders
4a6995be 116 */
2e92c10b 117 loaders: [
4a6995be 118
2e92c10b
C
119 /*
120 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
121 *
122 * See: https://github.com/s-panferov/awesome-typescript-loader
123 */
124 {
125 test: /\.ts$/,
126 loaders: [
127 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
128 'awesome-typescript-loader',
129 'angular2-template-loader'
130 ],
131 exclude: [/\.(spec|e2e)\.ts$/]
132 },
4a6995be 133
2e92c10b
C
134 /*
135 * Json loader support for *.json files.
136 *
137 * See: https://github.com/webpack/json-loader
138 */
139 {
140 test: /\.json$/,
141 loader: 'json-loader'
142 },
4a6995be 143
2e92c10b 144 {
ad22074a
C
145 test: /\.(sass|scss)$/,
146 loaders: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url', 'sass-loader?sourceMap']
2e92c10b 147 },
ad22074a
C
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' },
4a6995be 150
2e92c10b
C
151 /* Raw loader support for *.html
152 * Returns file content as string
153 *
154 * See: https://github.com/webpack/raw-loader
155 */
156 {
157 test: /\.html$/,
158 loader: 'raw-loader',
159 exclude: [ helpers.root('src/index.html') ]
160 }
4a6995be 161
2e92c10b
C
162 ]
163
164 },
165
166 sassLoader: {
167 precision: 10
168 },
4a6995be
C
169
170 /*
2e92c10b 171 * Add additional plugins to the compiler.
4a6995be 172 *
2e92c10b 173 * See: http://webpack.github.io/docs/configuration.html#plugins
4a6995be 174 */
2e92c10b
C
175 plugins: [
176 new AssetsPlugin({
177 path: helpers.root('dist'),
178 filename: 'webpack-assets.json',
179 prettyPrint: true
180 }),
181
182 /*
183 * Plugin: ForkCheckerPlugin
184 * Description: Do type checking in a separate process, so webpack don't need to wait.
185 *
186 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
187 */
188 new ForkCheckerPlugin(),
189
190 /*
191 * Plugin: CommonsChunkPlugin
192 * Description: Shares common code between the pages.
193 * It identifies common modules and put them into a commons chunk.
194 *
195 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
196 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
197 */
198 new webpack.optimize.CommonsChunkPlugin({
199 name: [ 'polyfills', 'vendor' ].reverse()
200 }),
201
d268c551
C
202 /**
203 * Plugin: ContextReplacementPlugin
204 * Description: Provides context to Angular's use of System.import
205 *
206 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
207 * See: https://github.com/angular/angular/issues/11580
208 */
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
213 ),
214
2e92c10b
C
215 /*
216 * Plugin: CopyWebpackPlugin
217 * Description: Copy files and directories in webpack.
218 *
219 * Copies project static assets.
220 *
221 * See: https://www.npmjs.com/package/copy-webpack-plugin
222 */
223 new CopyWebpackPlugin([
224 {
225 from: 'src/assets',
226 to: 'assets'
227 },
228 {
229 from: 'node_modules/webtorrent/webtorrent.min.js',
230 to: 'assets/webtorrent'
231 }
232 ]),
233
234 /*
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.
239 *
240 * See: https://github.com/ampedandwired/html-webpack-plugin
241 */
242 new HtmlWebpackPlugin({
243 template: 'src/index.html',
244 chunksSortMode: 'dependency'
245 }),
246
247 new WebpackNotifierPlugin({ alwaysNotify: true })
248 ],
4a6995be
C
249
250 /*
2e92c10b
C
251 * Include polyfills or mocks for various node stuff
252 * Description: Node configuration
4a6995be 253 *
2e92c10b 254 * See: https://webpack.github.io/docs/configuration.html#node
4a6995be 255 */
2e92c10b
C
256 node: {
257 global: 'window',
258 crypto: 'empty',
259 fs: 'empty',
260 events: true,
261 module: false,
262 clearImmediate: false,
263 setImmediate: false
264 }
4a6995be 265 }
4a6995be 266}