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

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