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 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* global __dirname */
  2. const process = require('process');
  3. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  4. /**
  5. * The URL of the Jitsi Meet deployment to be proxy to in the context of
  6. * development with webpack-dev-server.
  7. */
  8. const devServerProxyTarget
  9. = process.env.WEBPACK_DEV_SERVER_PROXY_TARGET || 'https://beta.meet.jit.si';
  10. const analyzeBundle = process.argv.indexOf('--analyze-bundle') !== -1;
  11. const minimize
  12. = process.argv.indexOf('-p') !== -1
  13. || process.argv.indexOf('--optimize-minimize') !== -1;
  14. // The base Webpack configuration to bundle the JavaScript artifacts of
  15. // jitsi-meet such as app.bundle.js and external_api.js.
  16. const config = {
  17. devServer: {
  18. https: true,
  19. inline: true,
  20. proxy: {
  21. '/': {
  22. bypass: devServerProxyBypass,
  23. secure: false,
  24. target: devServerProxyTarget
  25. }
  26. }
  27. },
  28. devtool: 'source-map',
  29. mode: minimize ? 'production' : 'development',
  30. module: {
  31. rules: [ {
  32. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  33. // as well.
  34. exclude: [
  35. new RegExp(`${__dirname}/node_modules/(?!js-utils)`)
  36. ],
  37. loader: 'babel-loader',
  38. options: {
  39. // XXX The require.resolve bellow solves failures to locate the
  40. // presets when lib-jitsi-meet, for example, is npm linked in
  41. // jitsi-meet.
  42. plugins: [
  43. require.resolve('@babel/plugin-transform-flow-strip-types'),
  44. require.resolve('@babel/plugin-proposal-class-properties'),
  45. require.resolve('@babel/plugin-proposal-export-default-from'),
  46. require.resolve('@babel/plugin-proposal-export-namespace-from'),
  47. require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
  48. require.resolve('@babel/plugin-proposal-optional-chaining')
  49. ],
  50. presets: [
  51. [
  52. require.resolve('@babel/preset-env'),
  53. // Tell babel to avoid compiling imports into CommonJS
  54. // so that webpack may do tree shaking.
  55. {
  56. modules: false,
  57. // Specify our target browsers so no transpiling is
  58. // done unnecessarily. For browsers not specified
  59. // here, the ES2015+ profile will be used.
  60. targets: {
  61. chrome: 58,
  62. electron: 2,
  63. firefox: 54,
  64. safari: 11
  65. }
  66. }
  67. ],
  68. require.resolve('@babel/preset-flow'),
  69. require.resolve('@babel/preset-react')
  70. ]
  71. },
  72. test: /\.jsx?$/
  73. }, {
  74. // Expose jquery as the globals $ and jQuery because it is expected
  75. // to be available in such a form by multiple jitsi-meet
  76. // dependencies including lib-jitsi-meet.
  77. loader: 'expose-loader?$!expose-loader?jQuery',
  78. test: /\/node_modules\/jquery\/.*\.js$/
  79. }, {
  80. // Allow CSS to be imported into JavaScript.
  81. test: /\.css$/,
  82. use: [
  83. 'style-loader',
  84. 'css-loader'
  85. ]
  86. }, {
  87. test: /\/node_modules\/@atlaskit\/modal-dialog\/.*\.js$/,
  88. resolve: {
  89. alias: {
  90. 'react-focus-lock': `${__dirname}/react/features/base/util/react-focus-lock-wrapper.js`
  91. }
  92. }
  93. }, {
  94. test: /\/react\/features\/base\/util\/react-focus-lock-wrapper.js$/,
  95. resolve: {
  96. alias: {
  97. 'react-focus-lock': `${__dirname}/node_modules/react-focus-lock`
  98. }
  99. }
  100. } ]
  101. },
  102. node: {
  103. // Allow the use of the real filename of the module being executed. By
  104. // default Webpack does not leak path-related information and provides a
  105. // value that is a mock (/index.js).
  106. __filename: true
  107. },
  108. optimization: {
  109. concatenateModules: minimize,
  110. minimize
  111. },
  112. output: {
  113. filename: `[name]${minimize ? '.min' : ''}.js`,
  114. path: `${__dirname}/build`,
  115. publicPath: '/libs/',
  116. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  117. },
  118. plugins: [
  119. analyzeBundle
  120. && new BundleAnalyzerPlugin({
  121. analyzerMode: 'disabled',
  122. generateStatsFile: true
  123. })
  124. ].filter(Boolean),
  125. resolve: {
  126. alias: {
  127. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  128. },
  129. aliasFields: [
  130. 'browser'
  131. ],
  132. extensions: [
  133. '.web.js',
  134. // Webpack defaults:
  135. '.js',
  136. '.json'
  137. ]
  138. }
  139. };
  140. module.exports = [
  141. Object.assign({}, config, {
  142. entry: {
  143. 'app.bundle': './app.js',
  144. 'device_selection_popup_bundle':
  145. './react/features/settings/popup.js',
  146. 'alwaysontop':
  147. './react/features/always-on-top/index.js',
  148. 'dial_in_info_bundle':
  149. './react/features/invite/components/dial-in-info-page',
  150. 'do_external_connect':
  151. './connection_optimization/do_external_connect.js',
  152. 'flacEncodeWorker':
  153. './react/features/local-recording/recording/flac/flacEncodeWorker.js',
  154. 'analytics-ga':
  155. './react/features/analytics/handlers/GoogleAnalyticsHandler.js'
  156. }
  157. }),
  158. Object.assign({}, config, {
  159. entry: {
  160. 'video-blur-effect': './react/features/stream-effects/blur/index.js'
  161. },
  162. output: Object.assign({}, config.output, {
  163. library: [ 'JitsiMeetJS', 'app', 'effects' ],
  164. libraryTarget: 'window'
  165. })
  166. }),
  167. // The Webpack configuration to bundle external_api.js (aka
  168. // JitsiMeetExternalAPI).
  169. Object.assign({}, config, {
  170. entry: {
  171. 'external_api': './modules/API/external/index.js'
  172. },
  173. output: Object.assign({}, config.output, {
  174. library: 'JitsiMeetExternalAPI',
  175. libraryTarget: 'umd'
  176. })
  177. })
  178. ];
  179. /**
  180. * Determines whether a specific (HTTP) request is to bypass the proxy of
  181. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  182. * which local file is to be served in response to the request.
  183. *
  184. * @param {Object} request - The (HTTP) request received by the proxy.
  185. * @returns {string|undefined} If the request is to be served by the proxy
  186. * target, undefined; otherwise, the path to the local file to be served.
  187. */
  188. function devServerProxyBypass({ path }) {
  189. if (path.startsWith('/css/') || path.startsWith('/doc/')
  190. || path.startsWith('/fonts/') || path.startsWith('/images/')
  191. || path.startsWith('/sounds/')
  192. || path.startsWith('/static/')) {
  193. return path;
  194. }
  195. const configs = module.exports;
  196. /* eslint-disable array-callback-return, indent */
  197. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  198. if (path.startsWith(c.output.publicPath)) {
  199. if (!minimize) {
  200. // Since webpack-dev-server is serving non-minimized
  201. // artifacts, serve them even if the minimized ones are
  202. // requested.
  203. Object.keys(c.entry).some(e => {
  204. const name = `${e}.min.js`;
  205. if (path.indexOf(name) !== -1) {
  206. // eslint-disable-next-line no-param-reassign
  207. path = path.replace(name, `${e}.js`);
  208. return true;
  209. }
  210. });
  211. }
  212. return true;
  213. }
  214. })) {
  215. return path;
  216. }
  217. /* eslint-enable array-callback-return, indent */
  218. }