您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

webpack.config.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. // Allow CSS to be imported into JavaScript.
  85. test: /\.css$/,
  86. use: [
  87. 'style-loader',
  88. 'css-loader'
  89. ]
  90. } ]
  91. },
  92. node: {
  93. // Allow the use of the real filename of the module being executed. By
  94. // default Webpack does not leak path-related information and provides a
  95. // value that is a mock (/index.js).
  96. __filename: true
  97. },
  98. output: {
  99. filename: `[name]${minimize ? '.min' : ''}.js`,
  100. path: `${__dirname}/build`,
  101. publicPath: '/libs/',
  102. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  103. },
  104. plugins,
  105. resolve: {
  106. alias: {
  107. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  108. },
  109. aliasFields: [
  110. 'browser'
  111. ],
  112. extensions: [
  113. '.web.js',
  114. // Webpack defaults:
  115. '.js',
  116. '.json'
  117. ]
  118. }
  119. };
  120. module.exports = [
  121. Object.assign({}, config, {
  122. entry: {
  123. 'app.bundle': './app.js',
  124. 'device_selection_popup_bundle':
  125. './react/features/settings/popup.js',
  126. 'alwaysontop':
  127. './react/features/always-on-top/index.js',
  128. 'dial_in_info_bundle': [
  129. // atlaskit does not support React 16 prop-types
  130. './react/features/base/react/prop-types-polyfill.js',
  131. './react/features/invite/components/dial-in-info-page'
  132. ],
  133. 'do_external_connect':
  134. './connection_optimization/do_external_connect.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. return path;
  161. }
  162. const configs = module.exports;
  163. /* eslint-disable array-callback-return, indent */
  164. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  165. if (path.startsWith(c.output.publicPath)) {
  166. if (!minimize) {
  167. // Since webpack-dev-server is serving non-minimized
  168. // artifacts, serve them even if the minimized ones are
  169. // requested.
  170. Object.keys(c.entry).some(e => {
  171. const name = `${e}.min.js`;
  172. if (path.indexOf(name) !== -1) {
  173. // eslint-disable-next-line no-param-reassign
  174. path = path.replace(name, `${e}.js`);
  175. return true;
  176. }
  177. });
  178. }
  179. return true;
  180. }
  181. })) {
  182. return path;
  183. }
  184. /* eslint-enable array-callback-return, indent */
  185. }