Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

webpack.config.js 11KB

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