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

webpack.config.js 11KB

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