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

webpack.config.js 10KB

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