hmr.ts 594 B

12345678910111213141516171819202122232425
  1. import type { Plugin } from 'vite';
  2. /**
  3. * TODO
  4. * Temporarily solve the Vite circular dependency problem, and wait for a better solution to fix it later. I don't know what problems this writing will bring.
  5. * @returns
  6. */
  7. export function configHmrPlugin(): Plugin {
  8. return {
  9. name: 'singleHMR',
  10. handleHotUpdate({ modules, file }) {
  11. if (file.match(/xml$/)) return [];
  12. modules.forEach((m) => {
  13. if (!m.url.match(/\.(css|less)/)) {
  14. m.importedModules = new Set();
  15. m.importers = new Set();
  16. }
  17. });
  18. return modules;
  19. },
  20. };
  21. }