get-webpack-version.js 727 B

123456789101112131415161718192021
  1. // eslint-disable-next-line import/no-extraneous-dependencies
  2. // require.main is undefined while running WebStorm code assistance analyzer of webpack.config.js
  3. if (!require.main) {
  4. require.main = { require };
  5. }
  6. const webpackVersion = require.main.require('webpack/package.json').version;
  7. /**
  8. * @param {boolean} [onlyMajor=true]
  9. * @return {string}
  10. */
  11. function getWebpackVersion(onlyMajor = true) {
  12. return onlyMajor ? webpackVersion.split('.')[0] : webpackVersion;
  13. }
  14. getWebpackVersion.IS_1 = getWebpackVersion() === '1';
  15. getWebpackVersion.IS_2 = getWebpackVersion() === '2';
  16. getWebpackVersion.IS_3 = getWebpackVersion() === '3';
  17. getWebpackVersion.IS_4 = getWebpackVersion() === '4';
  18. module.exports = getWebpackVersion;