
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
unenv-nightly
Advanced tools
<!-- automd:badges color=yellow packagephobia -->
[!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.
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 |
nodeCompat
: (default: true
)
alias
entries for Node.js builtins as <id>
and node:<id>
.inject
entries for Node.js globals global
, Buffer
, and process
.npmShims
: (default: false
)
alias
entries to replace npm packages like node-fetch
with lighter shims.resolve
: (default: false
) Resolve config values to absolute paths.overrides
: Additional overrides for env config.presets
: Additional presets (for example @cloudflare/unenv-preset
).unenv/
polyfillsYou 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 |
unenv
replaces Node.js built-in modules compatible with any runtime (view source).
// 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 */
});
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"
}
}
Published under the MIT license.
Made by @pi0 and community π
π€ auto updated with automd
FAQs
<!-- automd:badges color=yellow packagephobia -->
The npm package unenv-nightly receives a total of 314,615 weekly downloads. As such, unenv-nightly popularity was classified as popular.
We found that unenv-nightly demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Koreaβs Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.