globals.js 843 B

12345678910111213141516171819202122
  1. /**
  2. * Gets current bundle's global scope identifier for React Refresh.
  3. * @param {Record<string, string>} runtimeGlobals The Webpack runtime globals.
  4. * @returns {string} The React Refresh global scope within the Webpack bundle.
  5. */
  6. module.exports.getRefreshGlobalScope = (runtimeGlobals) => {
  7. return `${runtimeGlobals.require || '__webpack_require__'}.$Refresh$`;
  8. };
  9. /**
  10. * Gets current Webpack version according to features on the compiler instance.
  11. * @param {import('webpack').Compiler} compiler The current Webpack compiler instance.
  12. * @returns {number} The current Webpack version.
  13. */
  14. module.exports.getWebpackVersion = (compiler) => {
  15. if (!compiler.hooks) {
  16. throw new Error(`[ReactRefreshPlugin] Webpack version is not supported!`);
  17. }
  18. // Webpack v5+ implements compiler caching
  19. return 'cache' in compiler ? 5 : 4;
  20. };