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

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