Skip to content

Latest commit

 

History

History
88 lines (70 loc) · 1.66 KB

README.md

File metadata and controls

88 lines (70 loc) · 1.66 KB

do-ob logo

Vite Library Configuration

Base configuration for building a NodeJS library package with Vite. This configuration is only for modern ESM TypeScript projects. TypeScript can be toggled off.

Installation

Install the configuration package with NPM or PNPM.

npm install -D @do-ob/vite-lib-config
pnpm add -D @do-ob/vite-lib-config

Usage

Simply merge with this configuration in vite.config.ts.

import { defineConfig, mergeConfig } from 'vite';
import viteLibConfig from '@do-ob/vite-lib-config';

export default mergeConfig(
  viteLibConfig(),
  defineConfig({
    /** Your configurations here **/
  }),
);

Options

Options object that can be passed into the viteLibConfig function.

export interface ViteLibConfigOptions {
    /**
     * Custom library name.
     * 
     * By default, library name is generated from the package name.
     */
    name?: string;

    /**
     * The directory where the entry-point source files
     * (at the root of the directory tree) are located.
     * 
     * These are the entry files where you export your public API.
     * 
     * @default 'src'
     */
    srcDir?: string;

    /**
     * The Vite library formats to build.
     * 
     * @default ['es', 'cjs']
     */
    formats?: LibraryFormats[];

    /**
     * Enables/Disables TypeScript configurations.
     * 
     * @default true
     */
    typescript?: boolean;
}

Example

viteLibConfig({
  name: 'MyAwesomeLib',
  srcDir: 'src',
  formats: ['es', 'cjs', 'umd']
})