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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ]
  56. },
  57. test: /\.js$/
  58. } ]
  59. },
  60. node: {
  61. // Allow the use of the real filename of the module being executed. By
  62. // default Webpack does not leak path-related information and provides a
  63. // value that is a mock (/index.js).
  64. __filename: true
  65. },
  66. optimization: {
  67. concatenateModules: minimize
  68. },
  69. output: {
  70. filename: `[name]${minimize ? '.min' : ''}.js`,
  71. path: process.cwd(),
  72. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  73. },
  74. performance: {
  75. hints: minimize ? 'error' : false,
  76. maxAssetSize: 750 * 1024,
  77. maxEntrypointSize: 750 * 1024
  78. },
  79. plugins: [
  80. analyzeBundle
  81. && new BundleAnalyzerPlugin({
  82. analyzerMode: 'disabled',
  83. generateStatsFile: true
  84. })
  85. ].filter(Boolean)
  86. };