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

webpack.config.js 11KB

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