You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack-shared-config.js 3.2KB

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