unjs / jiti

Runtime Typescript and ESM support for Node.js
MIT License
1.51k stars 52 forks source link

Feature: Live reload #76

Open rizrmd opened 1 year ago

rizrmd commented 1 year ago

Hi, Great Job!

It would be nice if jiti can watch current project and live reload it when some file changes.

szmxx commented 10 months ago

So far, does jiti support watch mode?

pi0 commented 10 months ago

@szmxx Not yet but you can try listhen CLI which gives you jiti powered watch mode for any dev server.

szmxx commented 10 months ago

@pi0 Looking forward, I will try

noook commented 4 months ago

This repository does not have discussions enabled, and it's not exactly an issue, more of a question / follow-up on the --watch flag usage when it comes to a Discord bot development.

I'm in the process of modernizing the tools and I immediately thought of jiti to run my app. However during development it is necessary to be able to watch and re-run the app on save instead of cancelling the process, and running it again.

@pi0 you mentioned that we can use listhen in the meanwhile, however I'm not sure whether it is the right tool for this use case ?

Another solution would be to simply use bun with the watch flag also. I'm curious what's your opinion on what's the best tool for this

pi0 commented 4 months ago

@noook If your app is a HTTP server, you can use listhen that uses jiti and does this. If it is not, you can easily create a watcher with @parcel/watcher and inside it use a jiti import with cache disabled. Also using bun --watch is a good alternative I sometimes do that too.

I like to introduce a similar feature of the bun to jiti core for live reload but it is mainly less of a priority now and the next goal is v2 (https://github.com/unjs/jiti/issues/174) so maybe after that in 2.x 👍🏼

angelhdzmultimedia commented 3 months ago

Was about to ask for a way to achieve this, but found the answer myself hahaha! 🤯🎉🤩

Anyone needing live reload with jiti for tests, there's a temporary (or possibly perpetual) workaround:

pnpx nodemon --exec pnpx jiti path/to/file.ts.

teamunjs ⚡💚💛

ericclemmons commented 3 months ago

I've found https://github.com/pygy/esm-reload works pretty well, too.