Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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/(?!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. },
  133. optimization: {
  134. concatenateModules: minimize,
  135. minimize
  136. },
  137. output: {
  138. filename: `[name]${minimize ? '.min' : ''}.js`,
  139. path: `${__dirname}/build`,
  140. publicPath: '/libs/',
  141. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  142. },
  143. plugins: [
  144. analyzeBundle
  145. && new BundleAnalyzerPlugin({
  146. analyzerMode: 'disabled',
  147. generateStatsFile: true
  148. }),
  149. detectCircularDeps
  150. && new CircularDependencyPlugin({
  151. allowAsyncCycles: false,
  152. exclude: /node_modules/,
  153. failOnError: false
  154. })
  155. ].filter(Boolean),
  156. resolve: {
  157. alias: {
  158. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  159. },
  160. aliasFields: [
  161. 'browser'
  162. ],
  163. extensions: [
  164. '.web.js',
  165. // Webpack defaults:
  166. '.js',
  167. '.json'
  168. ]
  169. }
  170. };
  171. module.exports = [
  172. Object.assign({}, config, {
  173. entry: {
  174. 'app.bundle': './app.js'
  175. },
  176. performance: getPerformanceHints(4 * 1024 * 1024)
  177. }),
  178. Object.assign({}, config, {
  179. entry: {
  180. 'device_selection_popup_bundle': './react/features/settings/popup.js'
  181. },
  182. performance: getPerformanceHints(700 * 1024)
  183. }),
  184. Object.assign({}, config, {
  185. entry: {
  186. 'alwaysontop': './react/features/always-on-top/index.js'
  187. },
  188. performance: getPerformanceHints(400 * 1024)
  189. }),
  190. Object.assign({}, config, {
  191. entry: {
  192. 'dial_in_info_bundle': './react/features/invite/components/dial-in-info-page'
  193. },
  194. performance: getPerformanceHints(500 * 1024)
  195. }),
  196. Object.assign({}, config, {
  197. entry: {
  198. 'do_external_connect': './connection_optimization/do_external_connect.js'
  199. },
  200. performance: getPerformanceHints(5 * 1024)
  201. }),
  202. Object.assign({}, config, {
  203. entry: {
  204. 'flacEncodeWorker': './react/features/local-recording/recording/flac/flacEncodeWorker.js'
  205. },
  206. performance: getPerformanceHints(5 * 1024)
  207. }),
  208. Object.assign({}, config, {
  209. entry: {
  210. 'analytics-ga': './react/features/analytics/handlers/GoogleAnalyticsHandler.js'
  211. },
  212. performance: getPerformanceHints(5 * 1024)
  213. }),
  214. // Because both video-blur-effect and rnnoise-processor modules are loaded
  215. // in a lazy manner using the loadScript function with a hard coded name,
  216. // i.e.loadScript('libs/rnnoise-processor.min.js'), webpack dev server
  217. // won't know how to properly load them using the default config filename
  218. // and sourceMapFilename parameters which target libs without .min in dev
  219. // mode. Thus we change these modules to have the same filename in both
  220. // prod and dev mode.
  221. Object.assign({}, config, {
  222. entry: {
  223. 'video-blur-effect': './react/features/stream-effects/blur/index.js'
  224. },
  225. output: Object.assign({}, config.output, {
  226. library: [ 'JitsiMeetJS', 'app', 'effects' ],
  227. libraryTarget: 'window',
  228. filename: '[name].min.js',
  229. sourceMapFilename: '[name].min.map'
  230. }),
  231. performance: getPerformanceHints(1 * 1024 * 1024)
  232. }),
  233. Object.assign({}, config, {
  234. entry: {
  235. 'rnnoise-processor': './react/features/stream-effects/rnnoise/index.js'
  236. },
  237. node: {
  238. // Emscripten generated glue code "rnnoise.js" expects node fs module,
  239. // we need to specify this parameter so webpack knows how to properly
  240. // interpret it when encountered.
  241. fs: 'empty'
  242. },
  243. output: Object.assign({}, config.output, {
  244. library: [ 'JitsiMeetJS', 'app', 'effects', 'rnnoise' ],
  245. libraryTarget: 'window',
  246. filename: '[name].min.js',
  247. sourceMapFilename: '[name].min.map'
  248. }),
  249. performance: getPerformanceHints(30 * 1024)
  250. }),
  251. Object.assign({}, config, {
  252. entry: {
  253. 'external_api': './modules/API/external/index.js'
  254. },
  255. output: Object.assign({}, config.output, {
  256. library: 'JitsiMeetExternalAPI',
  257. libraryTarget: 'umd'
  258. }),
  259. performance: getPerformanceHints(30 * 1024)
  260. })
  261. ];
  262. /**
  263. * Determines whether a specific (HTTP) request is to bypass the proxy of
  264. * webpack-dev-server (i.e. is to be handled by the proxy target) and, if not,
  265. * which local file is to be served in response to the request.
  266. *
  267. * @param {Object} request - The (HTTP) request received by the proxy.
  268. * @returns {string|undefined} If the request is to be served by the proxy
  269. * target, undefined; otherwise, the path to the local file to be served.
  270. */
  271. function devServerProxyBypass({ path }) {
  272. if (path.startsWith('/css/') || path.startsWith('/doc/')
  273. || path.startsWith('/fonts/')
  274. || path.startsWith('/images/')
  275. || path.startsWith('/lang/')
  276. || path.startsWith('/sounds/')
  277. || path.startsWith('/static/')
  278. || path.endsWith('.wasm')) {
  279. return path;
  280. }
  281. const configs = module.exports;
  282. /* eslint-disable array-callback-return, indent */
  283. if ((Array.isArray(configs) ? configs : Array(configs)).some(c => {
  284. if (path.startsWith(c.output.publicPath)) {
  285. if (!minimize) {
  286. // Since webpack-dev-server is serving non-minimized
  287. // artifacts, serve them even if the minimized ones are
  288. // requested.
  289. return Object.keys(c.entry).some(e => {
  290. const name = `${e}.min.js`;
  291. if (path.indexOf(name) !== -1) {
  292. // eslint-disable-next-line no-param-reassign
  293. path = path.replace(name, `${e}.js`);
  294. return true;
  295. }
  296. });
  297. }
  298. }
  299. })) {
  300. return path;
  301. }
  302. if (path.startsWith('/libs/')) {
  303. return path;
  304. }
  305. }