reactiverse / es4x

🚀 fast JavaScript 4 Eclipse Vert.x
https://reactiverse.io/es4x/
Apache License 2.0
878 stars 75 forks source link

Hot Reloading of Code #551

Closed murphye closed 2 years ago

murphye commented 3 years ago

A Node (or even a Java) developer would expect hot reloading of code to be supported. Is this possible with ES4X? I do not see it documented.

pmlopes commented 3 years ago

Yes, hot reload is possible. I'm currently working on improving the cli support as one of the goals is to reduce the dependency on npm. Given that es4x is just a small frontend to vertx and therefore to vertx launcher, you can do hot reload like you would in vert.x.

Imagine you have index.js with:

print('Hello!')

You can run the script as:

es4x run --redeploy='index.js' index.js

redeploy is a list of paths to watch, you can point to a folder for example. If you then edit the script you will see something like:

es4x run --redeploy='index.js' js:index.js 
Watched paths: [/home/paulo/test/./index.js]
Starting the vert.x application in redeploy mode
Starting vert.x application...
7b3016de-91e2-4d62-a340-4b0a71817972-redeploy
Hello
Succeeded in deploying verticle
Redeploying!
Stopping vert.x application '7b3016de-91e2-4d62-a340-4b0a71817972-redeploy'
Application '7b3016de-91e2-4d62-a340-4b0a71817972-redeploy' terminated with status 0
Starting vert.x application...
7b3016de-91e2-4d62-a340-4b0a71817972-redeploy
Redeployment done in 66 ms.
Hello Again!
Succeeded in deploying verticle

You can also run actions before the redeploy using the --on-redeploy="cmd" which are useful, say if you're using typescript and need to compile before run.

murphye commented 2 years ago

@pmlopes Can you add to your docs? To a developer hot reload is expected now.

fanbitian commented 2 years ago

@pmlopes We also need hot reloading in our project. And I found the option --redeploy is work for a single file but not a folder. Can you provides a docs?

pmlopes commented 2 years ago

@fanbitian we're about to release vert.x 4.2.4 (hopefuly this week). And I'll update the docs for supporting directories.

If I'm not mistaken, this should already support directories, so it could be a setup/config issue. I'll try to prepare an example to test and use in the docs.