3.5.3 • Published 3 years ago

@microflows/nodevm v3.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

  • 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 moduleName / http(s), ipfs is planned

Install

npm install @microflows/nodevm

Getting start

Example

Async/Await Style

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();

Promise Style

import vm from "@microflows/nodevm";

console.log(
  vm("https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js").then(
    newService => newService().name
  )
);

Use with init

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 module directly

import vm from "@microflows/nodevm";

// will fetch react.js from https://www.jsdelivr.com/react
const react = vm('react')

Advance

vm function arguments

nametypedescription
urlstringremote module url
fetcherFetchercustom fetcher
runtimestring[]code exec before remote module
dependenciesobjectcustom dependencies (you donnot need this when using mfNode)

Using your own fetcher

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)

Add runtime attachment

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)

Use require

const vm = require('@microflows/nodevm').default;
console.log(
  vm("https://cdn.jsdelivr.net/gh/microflows/mfNode.js@publish/release/index.js").then(
    newService => newService().name
  )
);

Content Security Policy (CSP)

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.

Read more on CSP

License

Apache License, Version 2.0

Copyright 2021microflow]

This project is based on remote-module-loader

Contributors✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

3.5.3

3 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.3.5

3 years ago

3.3.4

3 years ago

3.3.3

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.3.2

3 years ago

3.1.0

3 years ago

1.0.0

3 years ago