JSPM

  • Created
  • Published
  • Downloads 2260033
  • Score
    100M100P100Q212251F
  • License MIT

Package Exports

  • unenv
  • unenv/runtime/_internal/types
  • unenv/runtime/_internal/utils
  • unenv/runtime/fetch/call
  • unenv/runtime/fetch/index
  • unenv/runtime/mock/empty
  • unenv/runtime/mock/noop
  • unenv/runtime/mock/proxy
  • unenv/runtime/node/http/consts
  • unenv/runtime/node/http/index
  • unenv/runtime/node/http/request
  • unenv/runtime/node/http/response
  • unenv/runtime/node/net/index
  • unenv/runtime/node/net/socket
  • unenv/runtime/node/stream/index
  • unenv/runtime/node/stream/readable
  • unenv/runtime/node/stream/writable
  • unenv/runtime/npm/consola
  • unenv/runtime/npm/debug
  • unenv/runtime/npm/mime
  • unenv/runtime/npm/mime-db
  • unenv/runtime/polyfill/fetch.node
  • unenv/runtime/polyfill/global
  • unenv/runtime/polyfill/process

Readme

unenv

Once upon a time, one server was all needed to have a website

... And then SPAs1 moved server code to browser

... And then SSR2 moved browser code to server

... And then Workers3 moved browser/server code to workers

... Workers are neither NodeJS with process or Browser with window

... Yet expected to run code that had to work both of them

[1] Single Page Applications

[2] Server Side Rendering

[3] https://workers.cloudflare.com, https://deno.com/deploy

¯\_(ツ)_/¯

unenv is a collection of modules, polyfills, shims and presets that work perfectly with any Javascript environemnt including Browsers, Workers, NodeJS or pure JavaScript. Goal is that final bundle works consistent regardless of running context yet not adding excessive polyfills.

Install

Install un as devDependency:

yarn add --dev unenv
# or
npm i -D unenv

Usage: Generated env config

Using env utility and builtin presets (node and nodeless), unenv will provide an abstract config that can be used in building pipelines (rollup.js, webpack, etc)

import { env, node, nodeless } from 'unenv'

const { alias, inject, polyfill, external } = env(...presets)

Usage: As a runtime library

Alternatively, instead of using env generator, you can cherry-pick and combine runtime utilities individually in your source.

Runtime library

NodeJS

net

stream

Mocking utilities

Shims

polyfills

License

MIT