Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

webpack.config.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. // babel-polyfill and fetch polyfill are required for IE11.
  129. 'babel-polyfill',
  130. 'whatwg-fetch',
  131. './app.js'
  132. ],
  133. 'device_selection_popup_bundle':
  134. './react/features/settings/popup.js',
  135. 'alwaysontop':
  136. './react/features/always-on-top/index.js',
  137. 'dial_in_info_bundle': [
  138. // babel-polyfill and fetch polyfill are required for IE11.
  139. 'babel-polyfill',
  140. 'whatwg-fetch',
  141. // atlaskit does not support React 16 prop-types
  142. './react/features/base/react/prop-types-polyfill.js',
  143. './react/features/invite/components/dial-in-info-page'
  144. ],
  145. 'do_external_connect':
  146. './connection_optimization/do_external_connect.js'
  147. }
  148. }),
  149. // The Webpack configuration to bundle external_api.js (aka
  150. // JitsiMeetExternalAPI).
  151. Object.assign({}, config, {
  152. entry: {
  153. 'external_api': [
  154. // XXX Required by at least IE11 at the time of this writing.
  155. 'babel-polyfill',
  156. './modules/API/external/index.js'
  157. ]
  158. },
  159. output: Object.assign({}, config.output, {
  160. library: 'JitsiMeetExternalAPI',
  161. libraryTarget: 'umd'
  162. })
  163. })
  164. ];
  165. /**
  166. * Determines whether a specific (HTTP) request is to bypass the proxy of
  167. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  168. * which local file is to be served in response to the request.
  169. *
  170. * @param {Object} request - The (HTTP) request received by the proxy.
  171. * @returns {string|undefined} If the request is to be served by the proxy
  172. * target, undefined; otherwise, the path to the local file to be served.
  173. */
  174. function devServerProxyBypass({ path }) {
  175. if (path.startsWith('/css/') || path.startsWith('/doc/')) {
  176. return path;
  177. }
  178. const configs = module.exports;
  179. /* eslint-disable array-callback-return, indent */
  180. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  181. if (path.startsWith(c.output.publicPath)) {
  182. if (!minimize) {
  183. // Since webpack-dev-server is serving non-minimized
  184. // artifacts, serve them even if the minimized ones are
  185. // requested.
  186. Object.keys(c.entry).some(e => {
  187. const name = `${e}.min.js`;
  188. if (path.indexOf(name) !== -1) {
  189. // eslint-disable-next-line no-param-reassign
  190. path = path.replace(name, `${e}.js`);
  191. return true;
  192. }
  193. });
  194. }
  195. return true;
  196. }
  197. })) {
  198. return path;
  199. }
  200. /* eslint-enable array-callback-return, indent */
  201. }