You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack.config.js 11KB

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