Replies: 1 comment 9 replies
-
There's load(id) {
if (id === '\0virtual:xxx') {
let result = [];
for (const file of glob("public/data/entries/**/*.json")) {
this.addWatchFile(file);
result.push(readJson(file));
}
return `export default ${JSON.stringify(output)}`
}
} |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If we provide a virtual module, vite currently does not know its "implicit" dependencies, as shown in #15504 and my own experiences.
For example: I have multiple *.json files in my
public/data
directory and I would like to aggregate them into one single index file. So I wrote a plugin, which iterates through all *.json files in the directory, parse them, and export the index as an object.However, if any of these *.json files changed, a hot reload needs to take place to reload the virtual module, and there is no shortcut to do this currently in vite (again, because vite has no idea of these "implicit" dependencies), and here is my workaround:
I wonder if this could become a feature of vite, where users explicitly tell vite the implicit dependencies through the plugin api, for example:
so that vite can automatically configure file watchers etc. and do the hot reload for me.
Beta Was this translation helpful? Give feedback.
All reactions