]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/config/webpack.common.js
Fix check script
[github/Chocobozzz/PeerTube.git] / client / config / webpack.common.js
CommitLineData
4a6995be
C
1const helpers = require('./helpers')
2
3/*
4 * Webpack Plugins
5 */
6
2e92c10b 7const AssetsPlugin = require('assets-webpack-plugin')
c16ce1de 8const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
d268c551 9const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
c16ce1de
C
10const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
11const CopyWebpackPlugin = require('copy-webpack-plugin')
12const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
13const HtmlWebpackPlugin = require('html-webpack-plugin')
4d19d2f1
C
14const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
15const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
c16ce1de
C
16const ngcWebpack = require('ngc-webpack')
17
66698b83 18const WebpackNotifierPlugin = require('webpack-notifier')
4a6995be
C
19
20/*
21 * Webpack Constants
22 */
23const METADATA = {
24 title: 'PeerTube',
ab32b0fc
C
25 baseUrl: '/',
26 isDevServer: helpers.isWebpackDevServer()
4a6995be
C
27}
28
29/*
30 * Webpack configuration
31 *
32 * See: http://webpack.github.io/docs/configuration.html#cli
33 */
2e92c10b 34module.exports = function (options) {
c16ce1de
C
35 const isProd = options.env === 'production'
36 const AOT = isProd
2e92c10b
C
37
38 return {
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: {
c16ce1de
C
56 'polyfills': './src/polyfills.browser.ts',
57 'main': AOT
58 ? './src/main.browser.aot.ts'
59 : './src/main.browser.ts'
2e92c10b 60 },
b20b5fed 61
4a6995be 62 /*
2e92c10b 63 * Options affecting the resolving of modules.
4a6995be 64 *
2e92c10b 65 * See: http://webpack.github.io/docs/configuration.html#resolve
4a6995be 66 */
2e92c10b
C
67 resolve: {
68 /*
69 * An array of extensions that should be used to resolve modules.
70 *
71 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
72 */
4d19d2f1 73 extensions: [ '.ts', '.js', '.json', '.scss' ],
2e92c10b 74
c16ce1de 75 modules: [ helpers.root('src'), helpers.root('node_modules') ],
e903c2f3
C
76
77 alias: {
78 'video.js': 'video.js/dist/alt/video.novtt'
79 }
2e92c10b 80 },
4a6995be
C
81
82 /*
2e92c10b 83 * Options affecting the normal modules.
4a6995be 84 *
2e92c10b 85 * See: http://webpack.github.io/docs/configuration.html#module
4a6995be 86 */
2e92c10b 87 module: {
4a6995be 88
4d19d2f1 89 rules: [
4a6995be 90
2e92c10b
C
91 /*
92 * Typescript loader support for .ts and Angular 2 async routes via .async.ts
93 *
94 * See: https://github.com/s-panferov/awesome-typescript-loader
95 */
96 {
97 test: /\.ts$/,
c16ce1de 98 use: [
2e92c10b 99 '@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
c16ce1de
C
100 'awesome-typescript-loader?{configFileName: "tsconfig.webpack.json"}',
101 'angular2-template-loader',
102 {
103 loader: 'ng-router-loader',
104 options: {
105 loader: 'async-system',
106 genDir: 'compiled',
107 aot: AOT
108 }
109 }
2e92c10b
C
110 ],
111 exclude: [/\.(spec|e2e)\.ts$/]
112 },
4a6995be 113
2e92c10b
C
114 /*
115 * Json loader support for *.json files.
116 *
117 * See: https://github.com/webpack/json-loader
118 */
119 {
120 test: /\.json$/,
121 loader: 'json-loader'
122 },
4a6995be 123
2e92c10b 124 {
ad22074a 125 test: /\.(sass|scss)$/,
c16ce1de
C
126 use: ['css-to-string-loader', 'css-loader?sourceMap', 'resolve-url-loader', 'sass-loader?sourceMap'],
127 exclude: [ helpers.root('src', 'styles') ]
2e92c10b 128 },
c16ce1de
C
129 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
130 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
4a6995be 131
2e92c10b
C
132 /* Raw loader support for *.html
133 * Returns file content as string
134 *
135 * See: https://github.com/webpack/raw-loader
136 */
137 {
138 test: /\.html$/,
139 loader: 'raw-loader',
3bb2c7f9 140 exclude: [ helpers.root('src/index.html'), helpers.root('src/standalone/videos/embed.html') ]
2e92c10b 141 }
4a6995be 142
2e92c10b
C
143 ]
144
145 },
146
4a6995be 147 /*
2e92c10b 148 * Add additional plugins to the compiler.
4a6995be 149 *
2e92c10b 150 * See: http://webpack.github.io/docs/configuration.html#plugins
4a6995be 151 */
2e92c10b
C
152 plugins: [
153 new AssetsPlugin({
154 path: helpers.root('dist'),
155 filename: 'webpack-assets.json',
156 prettyPrint: true
157 }),
158
159 /*
160 * Plugin: ForkCheckerPlugin
161 * Description: Do type checking in a separate process, so webpack don't need to wait.
162 *
163 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
164 */
c16ce1de 165 new CheckerPlugin(),
2e92c10b
C
166
167 /*
168 * Plugin: CommonsChunkPlugin
169 * Description: Shares common code between the pages.
170 * It identifies common modules and put them into a commons chunk.
171 *
172 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
173 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
174 */
c16ce1de
C
175 new CommonsChunkPlugin({
176 name: 'polyfills',
177 chunks: ['polyfills']
178 }),
179
180 // This enables tree shaking of the vendor modules
181 new CommonsChunkPlugin({
182 name: 'vendor',
183 chunks: ['main'],
184 minChunks: module => /node_modules\//.test(module.resource)
185 }),
186
187 // Specify the correct order the scripts will be injected in
188 new CommonsChunkPlugin({
189 name: ['polyfills', 'vendor'].reverse()
2e92c10b
C
190 }),
191
d268c551
C
192 /**
193 * Plugin: ContextReplacementPlugin
194 * Description: Provides context to Angular's use of System.import
195 *
196 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
197 * See: https://github.com/angular/angular/issues/11580
4d19d2f1 198 */
d268c551
C
199 new ContextReplacementPlugin(
200 // The (\\|\/) piece accounts for path separators in *nix and Windows
c16ce1de
C
201 /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
202 helpers.root('src'), // location of your src
203 {
204 // your Angular Async Route paths relative to this root directory
205 }
d268c551
C
206 ),
207
2e92c10b
C
208 /*
209 * Plugin: CopyWebpackPlugin
210 * Description: Copy files and directories in webpack.
211 *
212 * Copies project static assets.
213 *
214 * See: https://www.npmjs.com/package/copy-webpack-plugin
215 */
a8644408 216 // Used by embed.html
2e92c10b
C
217 new CopyWebpackPlugin([
218 {
219 from: 'src/assets',
220 to: 'assets'
221 },
222 {
223 from: 'node_modules/webtorrent/webtorrent.min.js',
224 to: 'assets/webtorrent'
3bb2c7f9
C
225 },
226 {
227 from: 'node_modules/video.js/dist/video.min.js',
228 to: 'assets/video-js'
229 },
230 {
231 from: 'node_modules/video.js/dist/video-js.min.css',
232 to: 'assets/video-js'
233 },
234 {
235 from: 'node_modules/videojs-dock/dist/videojs-dock.min.js',
236 to: 'assets/video-js'
237 },
238 {
239 from: 'node_modules/videojs-dock/dist/videojs-dock.css',
240 to: 'assets/video-js'
241 },
242 {
243 from: 'src/standalone',
244 to: 'standalone'
2e92c10b
C
245 }
246 ]),
247
248 /*
249 * Plugin: HtmlWebpackPlugin
250 * Description: Simplifies creation of HTML files to serve your webpack bundles.
251 * This is especially useful for webpack bundles that include a hash in the filename
252 * which changes every compilation.
253 *
254 * See: https://github.com/ampedandwired/html-webpack-plugin
255 */
256 new HtmlWebpackPlugin({
257 template: 'src/index.html',
4d19d2f1
C
258 title: METADATA.title,
259 chunksSortMode: 'dependency',
260 metadata: METADATA
261 }),
262
263 /*
264 * Plugin: ScriptExtHtmlWebpackPlugin
265 * Description: Enhances html-webpack-plugin functionality
266 * with different deployment options for your scripts including:
267 *
268 * See: https://github.com/numical/script-ext-html-webpack-plugin
269 */
270 new ScriptExtHtmlWebpackPlugin({
3bb2c7f9 271 sync: [ 'webtorrent.min.js' ],
4d19d2f1 272 defaultAttribute: 'defer'
2e92c10b
C
273 }),
274
4d19d2f1
C
275 new WebpackNotifierPlugin({ alwaysNotify: true }),
276
277 /**
278 * Plugin LoaderOptionsPlugin (experimental)
279 *
280 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
281 */
282 new LoaderOptionsPlugin({
283 options: {
284 sassLoader: {
285 precision: 10
286 }
287 }
c16ce1de
C
288 }),
289
290 // Fix Angular 2
291 new NormalModuleReplacementPlugin(
292 /facade(\\|\/)async/,
293 helpers.root('node_modules/@angular/core/src/facade/async.js')
294 ),
295 new NormalModuleReplacementPlugin(
296 /facade(\\|\/)collection/,
297 helpers.root('node_modules/@angular/core/src/facade/collection.js')
298 ),
299 new NormalModuleReplacementPlugin(
300 /facade(\\|\/)errors/,
301 helpers.root('node_modules/@angular/core/src/facade/errors.js')
302 ),
303 new NormalModuleReplacementPlugin(
304 /facade(\\|\/)lang/,
305 helpers.root('node_modules/@angular/core/src/facade/lang.js')
306 ),
307 new NormalModuleReplacementPlugin(
308 /facade(\\|\/)math/,
309 helpers.root('node_modules/@angular/core/src/facade/math.js')
310 ),
311
312 new ngcWebpack.NgcWebpackPlugin({
313 disabled: !AOT,
314 tsConfig: helpers.root('tsconfig.webpack.json'),
315 resourceOverride: helpers.root('config/resource-override.js')
4d19d2f1 316 })
2e92c10b 317 ],
4a6995be
C
318
319 /*
2e92c10b
C
320 * Include polyfills or mocks for various node stuff
321 * Description: Node configuration
4a6995be 322 *
2e92c10b 323 * See: https://webpack.github.io/docs/configuration.html#node
4a6995be 324 */
2e92c10b 325 node: {
4d19d2f1 326 global: 'true',
2e92c10b 327 crypto: 'empty',
4d19d2f1 328 process: true,
2e92c10b
C
329 module: false,
330 clearImmediate: false,
c16ce1de
C
331 setImmediate: false,
332 setInterval: false,
333 setTimeout: false
2e92c10b 334 }
4a6995be 335 }
4a6995be 336}