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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. '../styled/Modal': `${__dirname}/react/features/base/dialog/components/web/ThemedDialog.js`
  108. }
  109. }
  110. }, {
  111. test: /\/react\/features\/base\/util\/react-focus-lock-wrapper.js$/,
  112. resolve: {
  113. alias: {
  114. 'react-focus-lock': `${__dirname}/node_modules/react-focus-lock`
  115. }
  116. }
  117. }, {
  118. test: /\.svg$/,
  119. use: [ {
  120. loader: '@svgr/webpack',
  121. options: {
  122. dimensions: false,
  123. expandProps: 'start'
  124. }
  125. } ]
  126. } ]
  127. },
  128. node: {
  129. // Allow the use of the real filename of the module being executed. By
  130. // default Webpack does not leak path-related information and provides a
  131. // value that is a mock (/index.js).
  132. __filename: true,
  133. // Provide some empty Node modules (required by olm).
  134. crypto: 'empty',
  135. fs: 'empty'
  136. },
  137. optimization: {
  138. concatenateModules: minimize,
  139. minimize
  140. },
  141. output: {
  142. filename: `[name]${minimize ? '.min' : ''}.js`,
  143. path: `${__dirname}/build`,
  144. publicPath: '/libs/',
  145. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  146. },
  147. plugins: [
  148. analyzeBundle
  149. && new BundleAnalyzerPlugin({
  150. analyzerMode: 'disabled',
  151. generateStatsFile: true
  152. }),
  153. detectCircularDeps
  154. && new CircularDependencyPlugin({
  155. allowAsyncCycles: false,
  156. exclude: /node_modules/,
  157. failOnError: false
  158. })
  159. ].filter(Boolean),
  160. resolve: {
  161. alias: {
  162. 'focus-visible': 'focus-visible/dist/focus-visible.min.js',
  163. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  164. },
  165. aliasFields: [
  166. 'browser'
  167. ],
  168. extensions: [
  169. '.web.js',
  170. // Webpack defaults:
  171. '.js',
  172. '.json'
  173. ]
  174. }
  175. };
  176. module.exports = [
  177. Object.assign({}, config, {
  178. entry: {
  179. 'app.bundle': './app.js'
  180. },
  181. performance: getPerformanceHints(4 * 1024 * 1024)
  182. }),
  183. Object.assign({}, config, {
  184. entry: {
  185. 'device_selection_popup_bundle': './react/features/settings/popup.js'
  186. },
  187. performance: getPerformanceHints(750 * 1024)
  188. }),
  189. Object.assign({}, config, {
  190. entry: {
  191. 'alwaysontop': './react/features/always-on-top/index.js'
  192. },
  193. performance: getPerformanceHints(400 * 1024)
  194. }),
  195. Object.assign({}, config, {
  196. entry: {
  197. 'dial_in_info_bundle': './react/features/invite/components/dial-in-info-page'
  198. },
  199. performance: getPerformanceHints(500 * 1024)
  200. }),
  201. Object.assign({}, config, {
  202. entry: {
  203. 'do_external_connect': './connection_optimization/do_external_connect.js'
  204. },
  205. performance: getPerformanceHints(5 * 1024)
  206. }),
  207. Object.assign({}, config, {
  208. entry: {
  209. 'flacEncodeWorker': './react/features/local-recording/recording/flac/flacEncodeWorker.js'
  210. },
  211. performance: getPerformanceHints(5 * 1024)
  212. }),
  213. Object.assign({}, config, {
  214. entry: {
  215. 'analytics-ga': './react/features/analytics/handlers/GoogleAnalyticsHandler.js'
  216. },
  217. performance: getPerformanceHints(5 * 1024)
  218. }),
  219. Object.assign({}, config, {
  220. entry: {
  221. 'close3': './static/close3.js'
  222. },
  223. performance: getPerformanceHints(128 * 1024)
  224. }),
  225. // Because both video-blur-effect and rnnoise-processor modules are loaded
  226. // in a lazy manner using the loadScript function with a hard coded name,
  227. // i.e.loadScript('libs/rnnoise-processor.min.js'), webpack dev server
  228. // won't know how to properly load them using the default config filename
  229. // and sourceMapFilename parameters which target libs without .min in dev
  230. // mode. Thus we change these modules to have the same filename in both
  231. // prod and dev mode.
  232. Object.assign({}, config, {
  233. entry: {
  234. 'video-blur-effect': './react/features/stream-effects/blur/index.js'
  235. },
  236. output: Object.assign({}, config.output, {
  237. library: [ 'JitsiMeetJS', 'app', 'effects' ],
  238. libraryTarget: 'window',
  239. filename: '[name].min.js',
  240. sourceMapFilename: '[name].min.map'
  241. }),
  242. performance: getPerformanceHints(1 * 1024 * 1024)
  243. }),
  244. Object.assign({}, config, {
  245. entry: {
  246. 'rnnoise-processor': './react/features/stream-effects/rnnoise/index.js'
  247. },
  248. output: Object.assign({}, config.output, {
  249. library: [ 'JitsiMeetJS', 'app', 'effects', 'rnnoise' ],
  250. libraryTarget: 'window',
  251. filename: '[name].min.js',
  252. sourceMapFilename: '[name].min.map'
  253. }),
  254. performance: getPerformanceHints(30 * 1024)
  255. }),
  256. Object.assign({}, config, {
  257. entry: {
  258. 'external_api': './modules/API/external/index.js'
  259. },
  260. output: Object.assign({}, config.output, {
  261. library: 'JitsiMeetExternalAPI',
  262. libraryTarget: 'umd'
  263. }),
  264. performance: getPerformanceHints(35 * 1024)
  265. })
  266. ];
  267. /**
  268. * Determines whether a specific (HTTP) request is to bypass the proxy of
  269. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  270. * which local file is to be served in response to the request.
  271. *
  272. * @param {Object} request - The (HTTP) request received by the proxy.
  273. * @returns {string|undefined} If the request is to be served by the proxy
  274. * target, undefined; otherwise, the path to the local file to be served.
  275. */
  276. function devServerProxyBypass({ path }) {
  277. if (path.startsWith('/css/') || path.startsWith('/doc/')
  278. || path.startsWith('/fonts/')
  279. || path.startsWith('/images/')
  280. || path.startsWith('/lang/')
  281. || path.startsWith('/sounds/')
  282. || path.startsWith('/static/')
  283. || path.endsWith('.wasm')) {
  284. return path;
  285. }
  286. const configs = module.exports;
  287. /* eslint-disable array-callback-return, indent */
  288. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  289. if (path.startsWith(c.output.publicPath)) {
  290. if (!minimize) {
  291. // Since webpack-dev-server is serving non-minimized
  292. // artifacts, serve them even if the minimized ones are
  293. // requested.
  294. return Object.keys(c.entry).some(e => {
  295. const name = `${e}.min.js`;
  296. if (path.indexOf(name) !== -1) {
  297. // eslint-disable-next-line no-param-reassign
  298. path = path.replace(name, `${e}.js`);
  299. return true;
  300. }
  301. });
  302. }
  303. }
  304. })) {
  305. return path;
  306. }
  307. if (path.startsWith('/libs/')) {
  308. return path;
  309. }
  310. }