Library Mode
Build a package for npm instead of an app: ES, CommonJS, UMD and IIFE outputs, type declarations, extracted CSS and a check of your package.json exports.
New in 1.1.0
From the CLI
bash
npx lunx build --lib src/index.ts # ES + CommonJS + .d.ts npx lunx build --lib --formats es,umd --name MyLib # adds a <script> global build npx lunx build --lib --watch # rebuild on change
From config
typescriptlunx.config.ts
import { defineConfig } from 'lunx-dev'; export default defineConfig({ lib: { entry: { index: 'src/index.ts', utils: 'src/utils/index.ts' }, formats: ['es', 'cjs'], }, });
A vite.config with build.lib is read the same way.
What it does
- Externals:
dependencies,peerDependenciesand Node built-ins stay imports; devDependencies and your sources are bundled.externalandnoExternaladjust it. - Frameworks: Vue and Svelte components and Solid / Preact JSX compile as in app builds.
- CSS: CSS, Sass, Less and CSS modules are extracted to
style.css; assets are inlined. - Types:
.d.tsfiles come from Oxc's isolated declarations in milliseconds, or fromtscwhen an export has no explicit type. - package.json check:
main,module,typesandexportsmust point at files the build wrote; lunx suggests anexportsmap when they do not.
Options
| Field | Type | Default | Description |
|---|---|---|---|
| --lib [entry] | string | src/index.ts | Entry file, or several via lib.entry in config. |
| --formats | es,cjs,umd,iife | es,cjs | Output formats. |
| --name | string | — | Global name for umd / iife builds. |
| --dts / --no-dts | boolean | with tsconfig.json | Emit type declarations. |
| --outDir | string | dist | Output directory. |
Faster declarations
Give exported functions explicit return types. Then Oxc writes every
.d.ts without starting TypeScript.