Package Exports
- vm-worker
- vm-worker/dist/vm-worker.cjs.js
- vm-worker/dist/vm-worker.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vm-worker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
VM Worker
Tiny VM for browser to execute javascript modules in Web Worker.
Usage
App.js
import VM from 'vm-worker'
const vm = VM({
timeout: 100000, // default 100000ms
})
await vm.require([
{
path: '/dirA/a.js',
url: 'https://xxx.com/a.js',
},
{
path: '/dirB/b.js',
src: 'module.exports = require("../dirA/a")',
},
])
await vm.exec('/dirB/b.js', 1, 2) // => 3
vm.terminate()
a.js
module.exports = (a, b) => (a + b)
ECMAScript Modules
App.js
import VM from 'vm-worker'
import ESMPlugin from 'vm-worker/dist/plugins/esmodule.esm'
const vm = VM({
plugins: [
ESMPlugin(),
],
})
await vm.require([
{
path: '/dirA/a.js',
url: 'https://xxx.com/a.js',
},
{
path: '/dirB/b.js',
src: `import { plus } from "../dirA/a"
export default plus`,
},
])
await vm.exec('/dirB/b.js', 1, 2) // => 3
vm.terminate()
a.js
export function plus(a, b) {
return a + b
}
Installation
npm i vm-worker