@dario-hacking/vite-6-alpha-environment-provider-node-vm
v0.0.4
Published
Package that exports a `nodeVmEnvironmentProvider` function that can be used to set a Vite Environment to run code inside a [Node.js `vm` module](https://nodejs.org/api/vm.html).
Downloads
6
Readme
Vite Environment Provider Node-VM
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 [email protected] Environment API implementation.
Package Usage
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,
});