unjs/unenv
์๊ฐ
๐๏ธ ๋ธ๋ผ์ฐ์ ์ ์ฃ์ง ์์ปค๋ฅผ ํฌํจํ ๋ชจ๋ JavaScript ๋ฐํ์์ ์ํ Node.js ํธํ์ฑ
ํ๋ก๊ทธ๋๋ฐ ์ธ์ด ๋ฐ ๋ฐํ์์ธก์ ๋ ์คํ ์ฆ๊ฐ
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- ๊ธฐ๋ก ์์ง ์ค
์๋ก ๊ฒน์น๋ ๊ธฐ๊ฐ์ ์์ฆ๊ฐ๋์ด๋ฉฐ ์ผ๋ณ ํฉ๊ณ๊ฐ ์๋๋๋ค. ์ธก์ ๊ฐ์ด ์์ผ๋ฉด ๋น์ ๋ก๋๋ค. ์คํ๋ ๊ด์ฌ๋๋ฅผ ๋ํ๋ด๋ฉฐ ํ์ง์ ๋ณด์ฅํ์ง ์์ต๋๋ค.
README.md
Original๐๏ธ unenv
[!NOTE] You are on the development (v2) branch. Check out v1 for the current release.
unenv provides polyfills to add Node.js compatibility for any JavaScript runtime, including browsers and edge workers.
๐ Used by
Usage
The defineEnv utility can generate a target environment configuration.
import { defineEnv } from "unenv";
const { env } = defineEnv({
nodeCompat: true,
npmShims: true,
resolve: true,
overrides: {},
presets: [],
});
const { alias, inject, external, polyfill } = env;
You can then integrate the env object with your build tool:
| Bundler | alias |
inject |
external |
|---|---|---|---|
| rollup | @rollup/plugin-alias |
@rollup/plugin-inject |
external |
| rolldown | resolve.alias |
inject |
external |
| vite | resolve.alias |
@rollup/plugin-inject |
ssr.external |
| esbuild | alias |
inject |
external |
| rspack | resolve.alias |
- | externals |
| webpack | resolve.alias |
webpack-plugin-inject |
externals |
Options
nodeCompat: (default:true)- Add
aliasentries for Node.js builtins as<id>andnode:<id>. - Add
injectentries for Node.js globalsglobal,Buffer, andprocess.
- Add
npmShims: (default:false)- Add
aliasentries to replace npm packages likenode-fetchwith lighter shims.
- Add
resolve: (default:false) Resolve config values to absolute paths.overrides: Additional overrides for env config.presets: Additional presets (for example@cloudflare/unenv-preset).
unenv/ polyfills
You can also directly import unenv/ polyfills:
| Polyfills | Description | Source |
|---|---|---|
unenv/mock/* |
Mocking utils | src/runtime/mock |
unenv/node/* |
APIs compatible with Node.js API |
src/runtime/node |
unenv/npm/* |
NPM package shims | src/runtime/npm |
unenv/polyfill/* |
Global polyfills | src/runtime/polyfill |
unenv/web/* |
Subset of Web APIs | src/runtime/web |
Node.js compatibility
unenv replaces Node.js built-in modules compatible with any runtime (view source).
- โ node:assert
- โ node:assert/strict
- โ node:async_hooks
- โ node:buffer
- โ node:child_process
- โ node:cluster
- โ node:console
- โ node:constants
- โ node:crypto
- โ node:dgram
- โ node:diagnostics_channel
- โ node:dns
- โ node:dns/promises
- โ node:domain
- โ node:events
- โ node:fs
- โ node:fs/promises
- โ node:http
- โ node:http2
- โ node:https
- โ node:inspector
- โ node:inspector/promises
- โ node:module
- โ node:net
- โ node:os
- โ node:path
- โ node:path/posix
- โ node:path/win32
- โ node:perf_hooks
- โ node:process
- โ node:punycode
- โ node:querystring
- โ node:readline
- โ node:readline/promises
- โ node:repl
- โ node:stream
- โ node:stream/consumers
- โ node:stream/promises
- โ node:stream/web
- โ node:string_decoder
- โ node:sys
- โ node:timers
- โ node:timers/promises
- โ node:tls
- โ node:trace_events
- โ node:tty
- โ node:url
- โ node:util
- โ node:util/types
- โ node:v8
- โ node:vm
- โ node:wasi
- โ node:worker_threads
- โ node:zlib
Manual mocking
// Magic proxy to replace any unknown API
import MockProxy from "unenv/mock/proxy";
// You can also create named mocks
const lib = MockProxy.__createMock__("lib", {
/* overrides */
});
Nightly release channel
You can use the nightly release channel to try the latest changes in the main branch via unenv-nightly.
If directly using unenv in your project:
{
"devDependencies": {
"unenv": "npm:unenv-nightly"
}
}
If using unenv via another tool (Nuxt or Nitro) in your project:
{
"resolutions": {
"unenv": "npm:unenv-nightly"
}
}
License
Published under the MIT license.
Made by @pi0 and community ๐
๐ค auto updated with automd
๊ด๋ จ ํ๋ก์ ํธ ์ดํด๋ณด๊ธฐ
๋ถ๋ฌ์ค๋ ์คโฆ