npm

@dario-hacking/vite-6-alpha-environment-provider-node-vm
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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 vite@6.0.0-alpha.18 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,
});

You can see usage examples here and here.

Readme

Keywords

none

Package Sidebar

Install

npm i @dario-hacking/vite-6-alpha-environment-provider-node-vm

Weekly Downloads

0

Version

0.0.4

License

none

Unpacked Size

7.66 kB

Total Files

4

Last publish

Collaborators

  • dario.piotrowicz