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

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