index.cjs 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/index.ts
  2. var _path = require('path');
  3. var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
  4. var _picomatch = require('picomatch'); var _picomatch2 = _interopRequireDefault(_picomatch);
  5. var _vite = require('vite');
  6. function normalizePaths(root, path) {
  7. return (Array.isArray(path) ? path : [path]).map((path2) => _path.resolve.call(void 0, root, path2)).map(_vite.normalizePath);
  8. }
  9. var src_default = (paths, config = {}) => ({
  10. name: "vite-plugin-full-reload",
  11. apply: "serve",
  12. // NOTE: Enable globbing so that Vite keeps track of the template files.
  13. config: () => ({ server: { watch: { disableGlobbing: false } } }),
  14. configureServer({ watcher, ws, config: { logger } }) {
  15. const { root = process.cwd(), log = true, always = true, delay = 0 } = config;
  16. const files = normalizePaths(root, paths);
  17. const shouldReload = _picomatch2.default.call(void 0, files);
  18. const checkReload = (path) => {
  19. if (shouldReload(path)) {
  20. setTimeout(() => ws.send({ type: "full-reload", path: always ? "*" : path }), delay);
  21. if (log)
  22. logger.info(`${_picocolors2.default.green("full reload")} ${_picocolors2.default.dim(_path.relative.call(void 0, root, path))}`, { clear: true, timestamp: true });
  23. }
  24. };
  25. watcher.add(files);
  26. watcher.on("add", checkReload);
  27. watcher.on("change", checkReload);
  28. }
  29. });
  30. exports.default = src_default; exports.normalizePaths = normalizePaths;