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.config.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /**
  9. * Build a Performance configuration object for the given size.
  10. * See: https://webpack.js.org/configuration/performance/
  11. */
  12. function getPerformanceHints(size) {
  13. return {
  14. hints: minimize ? 'error' : false,
  15. maxAssetSize: size,
  16. maxEntrypointSize: size
  17. };
  18. }
  19. // The base Webpack configuration to bundle the JavaScript artifacts of
  20. // jitsi-meet such as app.bundle.js and external_api.js.
  21. const config = {
  22. devtool: 'source-map',
  23. mode: minimize ? 'production' : 'development',
  24. module: {
  25. rules: [ {
  26. // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React
  27. // as well.
  28. exclude: [
  29. new RegExp(`${__dirname}/node_modules/(?!js-utils)`)
  30. ],
  31. loader: 'babel-loader',
  32. options: {
  33. // XXX The require.resolve bellow solves failures to locate the
  34. // presets when lib-jitsi-meet, for example, is npm linked in
  35. // jitsi-meet.
  36. plugins: [
  37. require.resolve('@babel/plugin-transform-flow-strip-types'),
  38. require.resolve('@babel/plugin-proposal-class-properties'),
  39. require.resolve('@babel/plugin-proposal-export-default-from'),
  40. require.resolve('@babel/plugin-proposal-export-namespace-from'),
  41. require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
  42. require.resolve('@babel/plugin-proposal-optional-chaining')
  43. ],
  44. presets: [
  45. [
  46. require.resolve('@babel/preset-env'),
  47. // Tell babel to avoid compiling imports into CommonJS
  48. // so that webpack may do tree shaking.
  49. {
  50. modules: false,
  51. // Specify our target browsers so no transpiling is
  52. // done unnecessarily. For browsers not specified
  53. // here, the ES2015+ profile will be used.
  54. targets: {
  55. chrome: 58,
  56. electron: 2,
  57. firefox: 54,
  58. safari: 11
  59. }
  60. }
  61. ],
  62. require.resolve('@babel/preset-flow'),
  63. require.resolve('@babel/preset-react')
  64. ]
  65. },
  66. test: /\.jsx?$/
  67. }, {
  68. // Expose jquery as the globals $ and jQuery because it is expected
  69. // to be available in such a form by multiple jitsi-meet
  70. // dependencies including lib-jitsi-meet.
  71. loader: 'expose-loader?$!expose-loader?jQuery',
  72. test: /\/node_modules\/jquery\/.*\.js$/
  73. } ]
  74. },
  75. node: {
  76. // Allow the use of the real filename of the module being executed. By
  77. // default Webpack does not leak path-related information and provides a
  78. // value that is a mock (/index.js).
  79. __filename: true
  80. },
  81. optimization: {
  82. concatenateModules: minimize,
  83. minimize
  84. },
  85. output: {
  86. filename: `[name]${minimize ? '.min' : ''}.js`,
  87. path: `${__dirname}/libs`,
  88. publicPath: 'load-test/libs/',
  89. sourceMapFilename: `[name].${minimize ? 'min' : 'js'}.map`
  90. },
  91. plugins: [
  92. analyzeBundle
  93. && new BundleAnalyzerPlugin({
  94. analyzerMode: 'disabled',
  95. generateStatsFile: true
  96. })
  97. ].filter(Boolean),
  98. resolve: {
  99. alias: {
  100. jquery: `jquery/dist/jquery${minimize ? '.min' : ''}.js`
  101. },
  102. aliasFields: [
  103. 'browser'
  104. ],
  105. extensions: [
  106. '.web.js',
  107. // Webpack defaults:
  108. '.js',
  109. '.json'
  110. ]
  111. }
  112. };
  113. module.exports = [
  114. Object.assign({}, config, {
  115. entry: {
  116. 'load-test-participant': './load-test-participant.js'
  117. },
  118. performance: getPerformanceHints(3 * 1024 * 1024)
  119. })
  120. ];