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

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