Skip to content
stdlib
Esc
↑↓navigate↵open⌘Jpreview
On this page

Usage

Installation

npm install -D @monstermann/stdlib-transform
pnpm add -D @monstermann/stdlib-transform
yarn add -D @monstermann/stdlib-transform
bun add -D @monstermann/stdlib-transform
nub add -D @monstermann/stdlib-transform
aube add -D @monstermann/stdlib-transform

Setup

Vite, Rolldown, tsdown

import { stdlib } from "@monstermann/stdlib-transform"
import { defineConfig } from "vite"

export default defineConfig({
    plugins: [stdlib()],
})
import { stdlib } from "@monstermann/stdlib-transform"
import { defineConfig } from "rolldown"

export default defineConfig({
    input: "src/index.ts",
    plugins: [stdlib()],
})
import { stdlib } from "@monstermann/stdlib-transform"
import { defineConfig } from "tsdown"

export default defineConfig({
    entry: "src/index.ts",
    plugins: [stdlib()],
})

Bun

For Bun.build:

import { stdlibBun } from "@monstermann/stdlib-transform"

await Bun.build({
    entrypoints: ["./src/index.ts"],
    plugins: [stdlibBun()],
})

For bun run and bun test, register it in a preload:

import { stdlibBun } from "@monstermann/stdlib-transform"
import { plugin } from "bun"

plugin(stdlibBun())
preload = ["./preload.ts"]

[test]
preload = ["./preload.ts"]

Bun only uses the first plugin that returns something for a file. With other plugins, call transform(code, path) from your own instead.

Options

Option Default Description
include /\.m?[jt]sx?(?:\?.*)?$/ Only files whose path matches one of these are transformed.
exclude Files whose path matches one of these are skipped.
debug false true, or a RegExp of paths: prints what is being replaced.
enforce "pre" or "post", not for Bun.

Dependencies in node_modules are never transformed.