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

webpack.config.js 9.2KB

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