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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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('@babel/plugin-proposal-export-default-from'),
  44. require.resolve('@babel/plugin-proposal-export-namespace-from'),
  45. require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
  46. require.resolve('@babel/plugin-proposal-optional-chaining')
  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. test: /\/node_modules\/@atlaskit\/modal-dialog\/.*\.js$/,
  86. resolve: {
  87. alias: {
  88. 'react-focus-lock': `${__dirname}/react/features/base/util/react-focus-lock-wrapper.js`
  89. }
  90. }
  91. }, {
  92. test: /\/react\/features\/base\/util\/react-focus-lock-wrapper.js$/,
  93. resolve: {
  94. alias: {
  95. 'react-focus-lock': `${__dirname}/node_modules/react-focus-lock`
  96. }
  97. }
  98. } ]
  99. },
  100. node: {
  101. // Allow the use of the real filename of the module being executed. By
  102. // default Webpack does not leak path-related information and provides a
  103. // value that is a mock (/index.js).
  104. __filename: true
  105. },
  106. optimization: {
  107. concatenateModules: minimize,
  108. minimize
  109. },
  110. output: {
  111. filename: `[name]${minimize ? '.min' : ''}.js`,
  112. path: `${__dirname}/build`,
  113. publicPath: '/libs/',
  114. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  115. },
  116. resolve: {
  117. alias: {
  118. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  119. },
  120. aliasFields: [
  121. 'browser'
  122. ],
  123. extensions: [
  124. '.web.js',
  125. // Webpack defaults:
  126. '.js',
  127. '.json'
  128. ]
  129. }
  130. };
  131. module.exports = [
  132. Object.assign({}, config, {
  133. entry: {
  134. 'app.bundle': './app.js',
  135. 'device_selection_popup_bundle':
  136. './react/features/settings/popup.js',
  137. 'alwaysontop':
  138. './react/features/always-on-top/index.js',
  139. 'dial_in_info_bundle': [
  140. './react/features/invite/components/dial-in-info-page'
  141. ],
  142. 'do_external_connect':
  143. './connection_optimization/do_external_connect.js',
  144. 'flacEncodeWorker':
  145. './react/features/local-recording/'
  146. + 'recording/flac/flacEncodeWorker.js',
  147. 'analytics-ga':
  148. './react/features/analytics/handlers/GoogleAnalyticsHandler.js'
  149. }
  150. }),
  151. Object.assign({}, config, {
  152. entry: {
  153. 'video-blur-effect': './react/features/stream-effects/blur/index.js'
  154. },
  155. output: Object.assign({}, config.output, {
  156. library: [ 'JitsiMeetJS', 'app', 'effects' ],
  157. libraryTarget: 'window'
  158. })
  159. }),
  160. // The Webpack configuration to bundle external_api.js (aka
  161. // JitsiMeetExternalAPI).
  162. Object.assign({}, config, {
  163. entry: {
  164. 'external_api': './modules/API/external/index.js'
  165. },
  166. output: Object.assign({}, config.output, {
  167. library: 'JitsiMeetExternalAPI',
  168. libraryTarget: 'umd'
  169. })
  170. })
  171. ];
  172. /**
  173. * Determines whether a specific (HTTP) request is to bypass the proxy of
  174. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  175. * which local file is to be served in response to the request.
  176. *
  177. * @param {Object} request - The (HTTP) request received by the proxy.
  178. * @returns {string|undefined} If the request is to be served by the proxy
  179. * target, undefined; otherwise, the path to the local file to be served.
  180. */
  181. function devServerProxyBypass({ path }) {
  182. if (path.startsWith('/css/') || path.startsWith('/doc/')
  183. || path.startsWith('/fonts/') || path.startsWith('/images/')
  184. || path.startsWith('/sounds/')
  185. || path.startsWith('/static/')) {
  186. return path;
  187. }
  188. const configs = module.exports;
  189. /* eslint-disable array-callback-return, indent */
  190. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  191. if (path.startsWith(c.output.publicPath)) {
  192. if (!minimize) {
  193. // Since webpack-dev-server is serving non-minimized
  194. // artifacts, serve them even if the minimized ones are
  195. // requested.
  196. Object.keys(c.entry).some(e => {
  197. const name = `${e}.min.js`;
  198. if (path.indexOf(name) !== -1) {
  199. // eslint-disable-next-line no-param-reassign
  200. path = path.replace(name, `${e}.js`);
  201. return true;
  202. }
  203. });
  204. }
  205. return true;
  206. }
  207. })) {
  208. return path;
  209. }
  210. /* eslint-enable array-callback-return, indent */
  211. }