-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a way to clear import cache for some file #27820
Comments
The |
no it'll reload hole server/app wanna a way that you can just clear some file's import cache so you can reload that file without full restart. // a.js
console.log("hi") // b.js
await import("./a.js")
await import("./a.js") // no output
delete require.cache["./a.;s"]
await import("./a.js") |
https://github.com/steve02081504/fount/blob/master/src%2Fserver%2Fparts_loader.mjs |
Since ECMAScript specifies that ES modules are cached, unfortunately your proposal would violate the spec. |
It is possible to load a module again as a separate module by using search params. await import("./a.js");
await import("./a.js?2"); |
not work for my repo, just like this: //a.js
import b from 'b.js' // c.js
await import("./a.js");
await import("./a.js?2");// will not reload b.js, bad :( |
Why do you need it to reload? |
user may update part/reload a same name part, and the js files in part may change. |
Isn't that what the --watch flag is for? |
no I don't wanna restart all codes :( |
It's a dirty workaround, but you can use CommonJS |
same issue as before: //a.js
import b from 'b.js' // c.js
require("./a.js");
require("./a.js");// will not reload b.js, bad :( |
In the case of ConmonJS, |
can we add an obj like |
We can't. If you want to make it happen, you should encourage TC39 to change the ECMAScript specification. |
Why not use web workers? You can reload all modules by restarting the worker. If code inside a buggy module goes into an infinite loop, you probably wouldn't want the entire app to freeze. Using workers you also get the ability to terminate ill-behaved code. |
the parts of my repo offers entrypoints/files/functions, and they may share vars. web worker is hard for part writers to learn and understand, and hard for development and sharing values :) |
it'll useful for hot reload codes
The text was updated successfully, but these errors were encountered: