- Dynamically load and run JS module from remote for the Browser or Node.js.
- Lazy Load Modules to keep initial load times down and load modules just in time, similar to Webpack's code splitting.
- Update Remote Modules independent of the web application. Update a module without redeploying the web application.
- A new method of SSR, server-side rendering js instead of html.
- As fast as your native code.
- Support remote module dependency.
- Manage your pkg in both way of centralized and decentralized. Support moduleName / http(s), ipfs is planned.
- Only 11kb after compilation.
npm install @microflows/nodevm
import vm from "@microflows/nodevm";
async function main() {
const newService = await vm("https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js");
console.log(newService().name);
}
main();
import vm from "@microflows/nodevm";
console.log(
vm("https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js").then(
newService => newService().name
)
);
import { newVM } from "@microflows/nodevm";
// public cache
const vm = newVM()
console.log(
vm("https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js").then(
newService => newService().name
)
);
import vm from "@microflows/nodevm";
// will fetch react.js from https://www.jsdelivr.com/react
const react = vm('react')
name | type | description |
---|---|---|
url | string | remote module url |
fetcher | Fetcher | custom fetcher |
runtime | string[] | code exec before remote module |
dependencies | object | custom dependencies (you donnot need this when using mfNode) |
The default loader can be overridden if you want to use an alternate method.
This example uses axios
for the fetcher.
import vm from "@microflows/nodevm";
import axios from "axios";
const fetcher = url => axios.get(url).then(request => request.data);
vm(url:"https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js",fetcher:fetcher)
import vm from "@microflows/nodevm";
const const runtime = ["const __dirname = '/home'"]
vm(url:"https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js",runtime:runtime)
Sites with a content_security_policy
header set are likely to not work. CSP puts a restriction on using new Function
, which remote-module-loader
relies upon.
Apache License, Version 2.0
Copyright [2021] [microflow]
This project is based on remote-module-loader
Thanks goes to these wonderful people (emoji key):
joelnet 💻 |
SOVLOOKUP 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!