Package that exports a nodeVmEnvironmentProvider
function that can be used to set a Vite Environment to run code inside a Node.js vm
module.
[!NOTE] Based on the vite@6.0.0-alpha.18 Environment API implementation.
The package exposes the nodeVMEnvironmentProvider
function that can be used to create new environments that run code inside a node vm:
environments: {
myEnvironment: nodeVMEnvironmentProvider(),
}
this sets both a dev
and a build
environments (of course users can also process the nodeVMEnvironmentProvider
returned value to tweak the returned environments and/or use only one of them).
In the case of the dev environment, the environment instance is enhanced with an api
field that contains a getHandler
method, this is what can then be used to handle incoming requests (making sure that they are run inside the node vm):
const handler = await devEnv.api.getHandler({
entrypoint: myEntrypoint,
});