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

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