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

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