Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

webpack-shared-config.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* global __dirname */
  2. const { execSync } = require('child_process');
  3. const path = require('path');
  4. const process = require('process');
  5. const { IgnorePlugin, ProvidePlugin } = require('webpack');
  6. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  7. const devNull = process.platform === 'win32' ? 'nul' : '/dev/null';
  8. const commitHash = process.env.LIB_JITSI_MEET_COMMIT_HASH
  9. || execSync(`git rev-parse --short HEAD 2>${devNull} || echo development`)
  10. .toString()
  11. .trim();
  12. module.exports = (minimize, analyzeBundle) => {
  13. return {
  14. // The inline-source-map is used to allow debugging the unit tests with Karma
  15. devtool: minimize ? 'source-map' : 'inline-source-map',
  16. resolve: {
  17. alias: {
  18. 'jquery': require.resolve('jquery/dist/jquery.slim.min.js')
  19. },
  20. extensions: [ '', '.js', '.ts' ]
  21. },
  22. mode: minimize ? 'production' : 'development',
  23. module: {
  24. rules: [ {
  25. // Version this build of the lib-jitsi-meet library.
  26. loader: 'string-replace-loader',
  27. options: {
  28. flags: 'g',
  29. replace: commitHash,
  30. search: '{#COMMIT_HASH#}'
  31. },
  32. test: path.join(__dirname, 'JitsiMeetJS.ts')
  33. }, {
  34. // Transpile ES2015 (aka ES6) to ES5.
  35. loader: 'babel-loader',
  36. options: {
  37. presets: [
  38. [
  39. '@babel/preset-env',
  40. // Tell babel to avoid compiling imports into CommonJS
  41. // so that webpack may do tree shaking.
  42. {
  43. modules: false,
  44. // Specify our target browsers so no transpiling is
  45. // done unnecessarily. For browsers not specified
  46. // here, the ES2015+ profile will be used.
  47. targets: {
  48. chrome: 80,
  49. electron: 10,
  50. firefox: 68,
  51. safari: 14
  52. }
  53. }
  54. ],
  55. '@babel/preset-typescript'
  56. ]
  57. },
  58. test: /\.(js|ts)$/
  59. } ]
  60. },
  61. node: {
  62. // Allow the use of the real filename of the module being executed. By
  63. // default Webpack does not leak path-related information and provides a
  64. // value that is a mock (/index.js).
  65. __filename: true
  66. },
  67. optimization: {
  68. concatenateModules: minimize
  69. },
  70. output: {
  71. filename: `[name]${minimize ? '.min' : ''}.js`,
  72. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  73. },
  74. performance: {
  75. hints: minimize ? 'error' : false,
  76. maxAssetSize: 1.25 * 1024 * 1024,
  77. maxEntrypointSize: 1.25 * 1024 * 1024
  78. },
  79. plugins: [
  80. new IgnorePlugin({ resourceRegExp: /^(@xmldom\/xmldom|ws)$/ }),
  81. analyzeBundle
  82. && new BundleAnalyzerPlugin({
  83. analyzerMode: 'disabled',
  84. generateStatsFile: true
  85. }),
  86. !minimize
  87. && new ProvidePlugin({
  88. process: require.resolve('process/browser')
  89. })
  90. ].filter(Boolean)
  91. };
  92. };