normalizeOptions.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const { d, n } = require('../../options');
  2. /**
  3. * Normalizes the options for the plugin.
  4. * @param {import('../types').ReactRefreshPluginOptions} options Non-normalized plugin options.
  5. * @returns {import('../types').NormalizedPluginOptions} Normalized plugin options.
  6. */
  7. const normalizeOptions = (options) => {
  8. d(options, 'exclude', /node_modules/i);
  9. d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
  10. d(options, 'forceEnable');
  11. d(options, 'library');
  12. n(options, 'overlay', (overlay) => {
  13. /** @type {import('../types').NormalizedErrorOverlayOptions} */
  14. const defaults = {
  15. entry: require.resolve('../../client/ErrorOverlayEntry'),
  16. module: require.resolve('../../overlay'),
  17. sockIntegration: 'wds',
  18. };
  19. if (overlay === false) {
  20. return false;
  21. }
  22. if (typeof overlay === 'undefined' || overlay === true) {
  23. return defaults;
  24. }
  25. d(overlay, 'entry', defaults.entry);
  26. d(overlay, 'module', defaults.module);
  27. d(overlay, 'sockIntegration', defaults.sockIntegration);
  28. d(overlay, 'sockHost');
  29. d(overlay, 'sockPath');
  30. d(overlay, 'sockPort');
  31. d(overlay, 'sockProtocol');
  32. d(options, 'useURLPolyfill');
  33. return overlay;
  34. });
  35. return options;
  36. };
  37. module.exports = normalizeOptions;