Reload virtual module on demand
See original GitHub issueClear 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.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How do I reload a module if I imported (possibly all) objects ...
I found an easy solution: Import from the module and the module itself. Then use reload() as usual, but also redo the import...
Read more >RELOAD Modules and RESTART Components - TechDocs
Reload OPS/MVS modules and restart OPS/MVS components.
Read more >Restart the Processes on a FireSIGHT System and a ... - Cisco
This section describes how to restart the processes that run on a managed device. FirePOWER Appliance, ASA FirePOWER Module, and NGIPS Virtual Device....
Read more >Create, destroy, start, stop, and reboot a ProfitBricks virtual ...
Parameter Choices/Defaults Comments
bus. ‑ Choices: IDE. VIRTIO ← The bus type for the volume.
count. ‑ Default: 1 The number of virtual machines to...
Read more >Restarting the Management agents in ESXi (1003490)
Virtual machine creation may fail because agent is unable to retrieve ... Instead restart independent services using the /etc/init.d/module ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Re-opening this. We could expose a
server.invalidateModule
api to help invalidate a virtual module easily. The HMR update part has been fixed in #10324I see 👍 Was just tossing ideas. Not familiar with the module graph API myself. I’d expect invalidating would trigger HMR as well.