Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Reloads the server when a vue file under a certain folder gets deleted or created
- import fs from "fs";
- function touch(path) {
- const time = new Date();
- try {
- fs.utimesSync(path, time, time);
- } catch (err) {
- fs.closeSync(fs.openSync(path, "w"));
- }
- }
- // for "options" here I just pass "pages" in the vite config file when I init the plugin, feel free to fix this
- export default function FullRestart(options = "") {
- let configFile = "vite.config.js";
- return {
- name: "vite-plugin-restart",
- configureServer(server) {
- server.watcher.on("add", (path) => {
- if (options != "") {
- if (path.includes(options) && path.endsWith(".vue")) {
- touch(configFile);
- server.ws.send({ type: "full-reload" });
- }
- }
- });
- server.watcher.on("unlink", (path) => {
- if (options != "") {
- if (path.includes(options) && path.endsWith(".vue")) {
- touch(configFile);
- server.ws.send({ type: "full-reload" });
- }
- }
- });
- },
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement