Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

webpack.config.js 11KB

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