lunx.docs
DocsGuidesLibrary Mode

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, peerDependencies and Node built-ins stay imports; devDependencies and your sources are bundled. external and noExternal adjust 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.ts files come from Oxc's isolated declarations in milliseconds, or from tsc when an export has no explicit type.
  • package.json check: main, module, types and exports must point at files the build wrote; lunx suggests an exports map when they do not.

Options

FieldTypeDefaultDescription
--lib [entry]stringsrc/index.tsEntry file, or several via lib.entry in config.
--formatses,cjs,umd,iifees,cjsOutput formats.
--namestring—Global name for umd / iife builds.
--dts / --no-dtsbooleanwith tsconfig.jsonEmit type declarations.
--outDirstringdistOutput directory.
Faster declarations
Give exported functions explicit return types. Then Oxc writes every .d.ts without starting TypeScript.