unjs / unbuild

📦 A unified JavaScript build system
MIT License
2.35k stars 90 forks source link

Document "passive watcher" usage #265

Closed rijkvanzanten closed 5 months ago

rijkvanzanten commented 1 year ago

Describe the feature

Hi there! I've been very interested in trying out the recommended "Passive Watcher" alternative to watching. I was able to find the hidden unbuild --stub command through the issues, but don't know what the next step is supposed to be. I've tried running the output with node dist/index.mjs which does start the h3/listhen powered server, but doesn't restart it when the file change (so it doesn't watch). Using node's native --watch doesn't work either, as jiti doesn't use an "import", so Node's watcher doesn't recognize the file change.

I should be able to make it work with nodemon (eg nodemon --watch src dist/index.mjs), but I'm very curious to learn how this is supposed to work 🙂

Additional information

rijkvanzanten commented 1 year ago

Here's what I'm currently landing on using. Curious to hear your thoughts! If this is the recommended approach, I'm more than happy to open a PR to tweak the docs 👍🏻

    "scripts": {
        "build": "unbuild",
        "start": "node dist/index.mjs",
        "stub": "unbuild --stub",
        "dev": "node --watch-path=src dist/index.mjs"
    },

To run in production, run npm run build followed by npm start. For dev server usage, run npm run stub and npm run dev. Note: I was having some issues with --watch-path in Node 18. I've upgraded to v20 which seems to resolve those issues

so1ve commented 1 year ago

The stub mode means you don't have to build everytime once you changed the code. If you want to build it instantly, try to use privatenumber/pkgroll

rijkvanzanten commented 1 year ago

The stub mode means you don't have to build everytime once you changed the code. If you want to build it instantly, try to use privatenumber/pkgroll

Yeah! Though if that is all it's intended to do, I think the name "Watcher" is a tad misleading, as it doesn't "watch" like you'd expect from a --watch flag in other CLI tools 🙂

pi0 commented 5 months ago