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.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* global __dirname */
  2. const process = require('process');
  3. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  4. const analyzeBundle = process.argv.indexOf('--analyze-bundle') !== -1;
  5. const minimize
  6. = process.argv.indexOf('-p') !== -1
  7. || process.argv.indexOf('--optimize-minimize') !== -1;
  8. module.exports = {
  9. // The inline-source-map is used to allow debugging the unit tests with Karma
  10. devtool: minimize ? 'source-map' : 'inline-source-map',
  11. mode: minimize ? 'production' : 'development',
  12. module: {
  13. rules: [ {
  14. // Version this build of the lib-jitsi-meet library.
  15. loader: 'string-replace-loader',
  16. options: {
  17. flags: 'g',
  18. replace:
  19. process.env.LIB_JITSI_MEET_COMMIT_HASH || 'development',
  20. search: '{#COMMIT_HASH#}'
  21. },
  22. test: `${__dirname}/JitsiMeetJS.js`
  23. }, {
  24. // Transpile ES2015 (aka ES6) to ES5.
  25. exclude: [
  26. new RegExp(`${__dirname}/node_modules/(?!@jitsi/js-utils)`)
  27. ],
  28. loader: 'babel-loader',
  29. options: {
  30. presets: [
  31. [
  32. '@babel/preset-env',
  33. // Tell babel to avoid compiling imports into CommonJS
  34. // so that webpack may do tree shaking.
  35. {
  36. modules: false,
  37. // Specify our target browsers so no transpiling is
  38. // done unnecessarily. For browsers not specified
  39. // here, the ES2015+ profile will be used.
  40. targets: {
  41. chrome: 58,
  42. electron: 2,
  43. firefox: 54,
  44. safari: 11
  45. }
  46. }
  47. ],
  48. '@babel/preset-flow'
  49. ],
  50. plugins: [
  51. '@babel/plugin-transform-flow-strip-types',
  52. '@babel/plugin-proposal-class-properties',
  53. '@babel/plugin-proposal-optional-chaining',
  54. '@babel/plugin-proposal-export-namespace-from',
  55. '@babel/plugin-proposal-nullish-coalescing-operator'
  56. ]
  57. },
  58. test: /\.js$/
  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. path: process.cwd(),
  73. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  74. },
  75. performance: {
  76. hints: minimize ? 'error' : false,
  77. maxAssetSize: 750 * 1024,
  78. maxEntrypointSize: 750 * 1024
  79. },
  80. plugins: [
  81. analyzeBundle
  82. && new BundleAnalyzerPlugin({
  83. analyzerMode: 'disabled',
  84. generateStatsFile: true
  85. })
  86. ].filter(Boolean)
  87. };