Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

webpack.config.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /* global __dirname */
  2. const process = require('process');
  3. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  4. /**
  5. * The URL of the Jitsi Meet deployment to be proxy to in the context of
  6. * development with webpack-dev-server.
  7. */
  8. const devServerProxyTarget
  9. = process.env.WEBPACK_DEV_SERVER_PROXY_TARGET || 'https://alpha.jitsi.net';
  10. const analyzeBundle = process.argv.indexOf('--analyze-bundle') !== -1;
  11. const minimize
  12. = process.argv.indexOf('-p') !== -1
  13. || process.argv.indexOf('--optimize-minimize') !== -1;
  14. /**
  15. * Build a Performance configuration object for the given size.
  16. * See: https://webpack.js.org/configuration/performance/
  17. */
  18. function getPerformanceHints(size) {
  19. return {
  20. hints: minimize ? 'error' : false,
  21. maxAssetSize: size,
  22. maxEntrypointSize: size
  23. };
  24. }
  25. // The base Webpack configuration to bundle the JavaScript artifacts of
  26. // jitsi-meet such as app.bundle.js and external_api.js.
  27. const config = {
  28. devServer: {
  29. https: true,
  30. inline: true,
  31. proxy: {
  32. '/': {
  33. bypass: devServerProxyBypass,
  34. secure: false,
  35. target: devServerProxyTarget,
  36. headers: {
  37. 'Host': new URL(devServerProxyTarget).host
  38. }
  39. }
  40. }
  41. },
  42. devtool: 'source-map',
  43. mode: minimize ? 'production' : 'development',
  44. module: {
  45. rules: [ {
  46. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  47. // as well.
  48. exclude: [
  49. new RegExp(`${__dirname}/node_modules/(?!js-utils)`)
  50. ],
  51. loader: 'babel-loader',
  52. options: {
  53. // XXX The require.resolve bellow solves failures to locate the
  54. // presets when lib-jitsi-meet, for example, is npm linked in
  55. // jitsi-meet.
  56. plugins: [
  57. require.resolve('@babel/plugin-transform-flow-strip-types'),
  58. require.resolve('@babel/plugin-proposal-class-properties'),
  59. require.resolve('@babel/plugin-proposal-export-default-from'),
  60. require.resolve('@babel/plugin-proposal-export-namespace-from'),
  61. require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
  62. require.resolve('@babel/plugin-proposal-optional-chaining')
  63. ],
  64. presets: [
  65. [
  66. require.resolve('@babel/preset-env'),
  67. // Tell babel to avoid compiling imports into CommonJS
  68. // so that webpack may do tree shaking.
  69. {
  70. modules: false,
  71. // Specify our target browsers so no transpiling is
  72. // done unnecessarily. For browsers not specified
  73. // here, the ES2015+ profile will be used.
  74. targets: {
  75. chrome: 58,
  76. electron: 2,
  77. firefox: 54,
  78. safari: 11
  79. }
  80. }
  81. ],
  82. require.resolve('@babel/preset-flow'),
  83. require.resolve('@babel/preset-react')
  84. ]
  85. },
  86. test: /\.jsx?$/
  87. }, {
  88. // Expose jquery as the globals $ and jQuery because it is expected
  89. // to be available in such a form by multiple jitsi-meet
  90. // dependencies including lib-jitsi-meet.
  91. loader: 'expose-loader?$!expose-loader?jQuery',
  92. test: /\/node_modules\/jquery\/.*\.js$/
  93. }, {
  94. // Allow CSS to be imported into JavaScript.
  95. test: /\.css$/,
  96. use: [
  97. 'style-loader',
  98. 'css-loader'
  99. ]
  100. }, {
  101. test: /\/node_modules\/@atlaskit\/modal-dialog\/.*\.js$/,
  102. resolve: {
  103. alias: {
  104. 'react-focus-lock': `${__dirname}/react/features/base/util/react-focus-lock-wrapper.js`
  105. }
  106. }
  107. }, {
  108. test: /\/react\/features\/base\/util\/react-focus-lock-wrapper.js$/,
  109. resolve: {
  110. alias: {
  111. 'react-focus-lock': `${__dirname}/node_modules/react-focus-lock`
  112. }
  113. }
  114. }, {
  115. test: /\.svg$/,
  116. use: [ {
  117. loader: '@svgr/webpack',
  118. options: {
  119. dimensions: false,
  120. expandProps: 'start'
  121. }
  122. } ]
  123. } ]
  124. },
  125. node: {
  126. // Allow the use of the real filename of the module being executed. By
  127. // default Webpack does not leak path-related information and provides a
  128. // value that is a mock (/index.js).
  129. __filename: true
  130. },
  131. optimization: {
  132. concatenateModules: minimize,
  133. minimize
  134. },
  135. output: {
  136. filename: `[name]${minimize ? '.min' : ''}.js`,
  137. path: `${__dirname}/build`,
  138. publicPath: '/libs/',
  139. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  140. },
  141. plugins: [
  142. analyzeBundle
  143. && new BundleAnalyzerPlugin({
  144. analyzerMode: 'disabled',
  145. generateStatsFile: true
  146. })
  147. ].filter(Boolean),
  148. resolve: {
  149. alias: {
  150. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  151. },
  152. aliasFields: [
  153. 'browser'
  154. ],
  155. extensions: [
  156. '.web.js',
  157. // Webpack defaults:
  158. '.js',
  159. '.json'
  160. ]
  161. }
  162. };
  163. module.exports = [
  164. Object.assign({}, config, {
  165. entry: {
  166. 'app.bundle': './app.js'
  167. },
  168. performance: getPerformanceHints(4 * 1024 * 1024)
  169. }),
  170. Object.assign({}, config, {
  171. entry: {
  172. 'device_selection_popup_bundle': './react/features/settings/popup.js'
  173. },
  174. performance: getPerformanceHints(700 * 1024)
  175. }),
  176. Object.assign({}, config, {
  177. entry: {
  178. 'alwaysontop': './react/features/always-on-top/index.js'
  179. },
  180. performance: getPerformanceHints(400 * 1024)
  181. }),
  182. Object.assign({}, config, {
  183. entry: {
  184. 'dial_in_info_bundle': './react/features/invite/components/dial-in-info-page'
  185. },
  186. performance: getPerformanceHints(500 * 1024)
  187. }),
  188. Object.assign({}, config, {
  189. entry: {
  190. 'do_external_connect': './connection_optimization/do_external_connect.js'
  191. },
  192. performance: getPerformanceHints(5 * 1024)
  193. }),
  194. Object.assign({}, config, {
  195. entry: {
  196. 'flacEncodeWorker': './react/features/local-recording/recording/flac/flacEncodeWorker.js'
  197. },
  198. performance: getPerformanceHints(5 * 1024)
  199. }),
  200. Object.assign({}, config, {
  201. entry: {
  202. 'analytics-ga': './react/features/analytics/handlers/GoogleAnalyticsHandler.js'
  203. },
  204. performance: getPerformanceHints(5 * 1024)
  205. }),
  206. // Because both video-blur-effect and rnnoise-processor modules are loaded
  207. // in a lazy manner using the loadScript function with a hard coded name,
  208. // i.e.loadScript('libs/rnnoise-processor.min.js'), webpack dev server
  209. // won't know how to properly load them using the default config filename
  210. // and sourceMapFilename parameters which target libs without .min in dev
  211. // mode. Thus we change these modules to have the same filename in both
  212. // prod and dev mode.
  213. Object.assign({}, config, {
  214. entry: {
  215. 'video-blur-effect': './react/features/stream-effects/blur/index.js'
  216. },
  217. output: Object.assign({}, config.output, {
  218. library: [ 'JitsiMeetJS', 'app', 'effects' ],
  219. libraryTarget: 'window',
  220. filename: '[name].min.js',
  221. sourceMapFilename: '[name].min.map'
  222. }),
  223. performance: getPerformanceHints(1 * 1024 * 1024)
  224. }),
  225. Object.assign({}, config, {
  226. entry: {
  227. 'rnnoise-processor': './react/features/stream-effects/rnnoise/index.js'
  228. },
  229. node: {
  230. // Emscripten generated glue code "rnnoise.js" expects node fs module,
  231. // we need to specify this parameter so webpack knows how to properly
  232. // interpret it when encountered.
  233. fs: 'empty'
  234. },
  235. output: Object.assign({}, config.output, {
  236. library: [ 'JitsiMeetJS', 'app', 'effects', 'rnnoise' ],
  237. libraryTarget: 'window',
  238. filename: '[name].min.js',
  239. sourceMapFilename: '[name].min.map'
  240. }),
  241. performance: getPerformanceHints(30 * 1024)
  242. }),
  243. Object.assign({}, config, {
  244. entry: {
  245. 'external_api': './modules/API/external/index.js'
  246. },
  247. output: Object.assign({}, config.output, {
  248. library: 'JitsiMeetExternalAPI',
  249. libraryTarget: 'umd'
  250. }),
  251. performance: getPerformanceHints(30 * 1024)
  252. })
  253. ];
  254. /**
  255. * Determines whether a specific (HTTP) request is to bypass the proxy of
  256. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  257. * which local file is to be served in response to the request.
  258. *
  259. * @param {Object} request - The (HTTP) request received by the proxy.
  260. * @returns {string|undefined} If the request is to be served by the proxy
  261. * target, undefined; otherwise, the path to the local file to be served.
  262. */
  263. function devServerProxyBypass({ path }) {
  264. if (path.startsWith('/css/') || path.startsWith('/doc/')
  265. || path.startsWith('/fonts/') || path.startsWith('/images/')
  266. || path.startsWith('/lang/')
  267. || path.startsWith('/sounds/')
  268. || path.startsWith('/static/')
  269. || path.endsWith('.wasm')) {
  270. return path;
  271. }
  272. const configs = module.exports;
  273. /* eslint-disable array-callback-return, indent */
  274. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  275. if (path.startsWith(c.output.publicPath)) {
  276. if (!minimize) {
  277. // Since webpack-dev-server is serving non-minimized
  278. // artifacts, serve them even if the minimized ones are
  279. // requested.
  280. return Object.keys(c.entry).some(e => {
  281. const name = `${e}.min.js`;
  282. if (path.indexOf(name) !== -1) {
  283. // eslint-disable-next-line no-param-reassign
  284. path = path.replace(name, `${e}.js`);
  285. return true;
  286. }
  287. });
  288. }
  289. }
  290. })) {
  291. return path;
  292. }
  293. if (path.startsWith('/libs/')) {
  294. return path;
  295. }
  296. }