UNPKG

1 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.watchPlugin = void 0;
7const debounce_1 = __importDefault(require("debounce"));
8function watchPlugin() {
9 return {
10 name: 'watch',
11 injectWebSocket: true,
12 serverStart({ fileWatcher, webSockets }) {
13 if (!webSockets) {
14 throw new Error('Cannot use watch mode when web sockets are disabled.');
15 }
16 function onFileChanged() {
17 webSockets.sendImport('data:text/javascript,window.location.reload()');
18 }
19 const onChange = (0, debounce_1.default)(onFileChanged, 100);
20 fileWatcher.addListener('change', onChange);
21 fileWatcher.addListener('unlink', onChange);
22 },
23 };
24}
25exports.watchPlugin = watchPlugin;
26//# sourceMappingURL=watchPlugin.js.map
\No newline at end of file