lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.24k stars 65 forks source link

feat: close preview automatically option #168

Closed henrikvilhelmberglund closed 3 weeks ago

henrikvilhelmberglund commented 3 weeks ago

This PR adds a server.closePreviewAutomatically option (default false) which automatically closes the preview server (npm run preview) after 3000ms (arbitrary number).

No idea if this is something anyone wants (feel free to close if not) but to me it seems like the preview server is only used for getting the script data to the extension so might as well close it automatically to make going from dev to build and back a bit smoother.

I also have no idea what I'm doing so feel free to edit.

Usage: vite.config.ts

server: {
        closePreviewAutomatically: true
      },

package.json (not needed but can be nice)

    "build": "vite build",
    "postbuild": "vite preview",

Run npm run build, it builds, previews to let you reimport the script and closes automatically. Voila!

lisonge commented 3 weeks ago

I think this feature is not very useful

You can implement this feature by adding your plugin to the plugin list of vite.config.ts

lisonge commented 3 weeks ago

maybe you just want like this

chrome "D:\User\Documents\Project\vite-plugin-monkey\playground\solid-ts\dist\solid-ts.user.js"
henrikvilhelmberglund commented 3 weeks ago

maybe you just want like this

chrome "D:\User\Documents\Project\vite-plugin-monkey\playground\solid-ts\dist\solid-ts.user.js"

I tested something like this but I end up with an empty page which was also a bit annoying, but I can just use my fork.