Better vite.config handling
YPetremann opened this issue Β· comments
Y.Petremann commented
Hi!
Firstly, thanks for your work on this project!
Today I used patch-package to patch vite-plugin-restart@0.1.1
for the project I'm working on.
My project usually use multiple vite instance and therefore multiple vite config files, so I managed to automaticaly detect configFIle and then I've put a condition to prevent touching the file if it's vite config file.
Here is the diff that solved my problem:
diff --git a/node_modules/vite-plugin-restart/dist/index.js b/node_modules/vite-plugin-restart/dist/index.js
index 4410e6d..88311e8 100644
--- a/node_modules/vite-plugin-restart/dist/index.js
+++ b/node_modules/vite-plugin-restart/dist/index.js
@@ -146,8 +146,7 @@ function VitePluginRestart(options = {}) {
c2.server.watch.disableGlobbing = false;
},
configResolved(config) {
- if (import_fs.default.existsSync("vite.config.ts"))
- configFile = "vite.config.ts";
+ configFile = config.configFile;
root = config.root;
restartGlobs = toArray(options.restart).map((i2) => import_path.default.posix.join(root, i2));
reloadGlobs = toArray(options.reload).map((i2) => import_path.default.posix.join(root, i2));
@@ -161,6 +160,7 @@ function VitePluginRestart(options = {}) {
server.watcher.on("change", handleFileChange);
server.watcher.on("unlink", handleFileChange);
function handleFileChange(file) {
+ if (file === configFile) return;
if (import_micromatch.default.isMatch(file, restartGlobs)) {
timerState = "restart";
schedule(() => {
This issue body was partially generated by patch-package.