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

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