-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Labels
Description
Clear and concise description of the problem
As a developer I want to be able to reload a specific virtual module on demand via vite's Server API.
The idea is that the contents of that virtual module change upon an external event / conditon. I want to be able
to manually invalidate such module and reload it (and all modules who depend on it) on demand without restarting the whole server.
Suggested solution
const virtualModuleId = 'virtual:example'
const resolvedVirtualModuleId = '\0' + virtualModuleId
const custom = {
name: 'example',
enforce: 'pre',
resolveId: (id) => {
if (id === virtualModuleId) {
return resolvedVirtualModuleId
}
},
load: (id) => {
if (id === resolvedVirtualModuleId) {
return `...`
}
},
}
const server = await createServer({
plugins: [custom],
...
})
// For demo purposes, this is an external condition.
setInterval(() => {
// This is what I would expect somehow.
server.reloadModule(resolvedVirtualModuleId)
}, 5000)
await server.listen()
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
ivands and iksakuweineel and frandiox