Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

notbundle

caoxiemeihao2.1kMIT0.4.0TypeScript support: included

Inspired by Vite's Not Bundle, building ts for use in Node.js.

unbundle, bundle, build

readme

notbundle

Inspired by Vite's Not Bundle, building ts for use in Node.js.

NPM version NPM Downloads

  • 🚀 High-performance (Based on swc)
  • ⚡️ Support Plugin (Like Vite's plugin)
  • 🌱 Really simple (Few APIs)

Install

npm i notbundle

Usage

import {
  type Configuration,
  build,
  watch,
} from 'notbundle'

const config: Configuration = {
  include: ['src'],
  output: 'dist',
}

build(config)
// or
watch(config)

JavaScript API

import {
  type Plugin,
  type Configuration,
  type ResolvedConfig,
  resolveConfig,

  type BuildResult,
  build,
  type FSWatcher ,
  watch,

  // For custom logger
  colours,
  // Convert path to POSIX
  normalizePath,
} from 'notbundle'

API (Define)

Configuration
export interface Configuration {
  /** @default process.cwd() */
  root?: string
  /**
   * `directory` | `filename` | `glob`
   * 
   * Must be a relative path, which will be calculated based on the `root`.  
   * If it is an absolute path, it can only be a subpath of root.  
   * Otherwise it will cause the output file path to be calculated incorrectly.  
   */
  include: string[]
  /**
   * Output Directory.
   * If not set, the build result will be returned instead of being written to the file.
   */
  output?: string
  /** Like Vite's plugin */
  plugins?: {
    name: string
    configResolved?: (config: ResolvedConfig) => void | Promise<void>
    /** Triggered by `include` file changes. You can emit some files in this hooks. */
    onwatch?: (envet: 'add' | 'change' | 'addDir' | 'unlink' | 'unlinkDir', path: string) => void
    /** Triggered by changes in `extensions` files in include */
    transform?: (args: {
      /** Raw filename */
      filename: string
      code: string
      /** Skip subsequent transform hooks */
      done: () => void
    }) => string | null | void | import('@swc/core').Output | Promise<string | null | void | import('@swc/core').Output>
    /** Triggered when `transform()` ends or a file in `extensions` is removed */
    ondone?: (args: {
      filename: string
      code: string
      map?: string
      destname?: string
    }) => void
  }[],
  /** Custom log. If `logger` is passed, all logs will be input this option */
  logger?: {
    [type in 'error' | 'info' | 'success' | 'warn' | 'log']?: (...message: string[]) => void
  },
  /** Options of swc `transform()` */
  transformOptions?: import('@swc/core').Options
  /** Options of `chokidar.watch()` */
  watch?: import('chokidar').WatchOptions
}
ResolvedConfig
export interface ResolvedConfig {
  /** Absolute path */
  root: string
  /** Relative path */
  include: string[]
  /** Absolute path */
  output?: string
  plugins: NonNullable<Configuration['plugins']>
  logger: Required<NonNullable<Configuration['logger']>>
  /** Options of swc `transform()` */
  transformOptions: import('@swc/core').Options

  config: Configuration
  /** @default ['.ts', '.tsx', '.js', '.jsx'] */
  extensions: string[]
  /** Internal functions (🚨 Experimental) */
  experimental: {
    /** Only files of type `config.extensions` are included */
    include2files: (config: ResolvedConfig, include?: string[]) => string[]
    include2globs: (config: ResolvedConfig, include?: string[]) => string[]
    /** If include contains only one item, it will remove 1 level of dir 🤔 */
    input2output: (config: ResolvedConfig, filename: string) => string | undefined
  }
}

changelog

0.4.0 (2023-02-18)

  • 9c8a4f9 refactor: input2output instead replace2dest

0.3.4 (2023-01-07)

  • 525015e chore: cleanup
  • 0d61b9b feat: ondone support Promise

0.3.3 (2022-12-27)

  • ef98ee9 fix: include2globs try resolve files

0.3.2 (2022-12-26)

  • 952ccd8 fix: assign default node version
  • e4773cb feat: export type Plugin

0.3.1 (2022-12-25)

  • f804b6d fix: sourcemap warn
  • c4e29fa fix: removable plugin

0.3.0 (2022-12-24)

  • 985ba83 feat: test 🌱
  • ae03e06 refactor!: swc instead esbuild

0.2.1 (2022-12-22)

  • 87b4da1 fix: buildFile instead build, avoid resolveConfig repeat execution.

0.2.0 (2022-12-21)

  • 55d643a docs: v0.2.0
  • 2dd6862 refactor!: redefine export members
  • a183d0f refactor!: remove watcher in ResolvedConfig`
  • bcf3e6c feat: support custom logger
  • c9a144c feat: watch always return FSWatcher

0.1.1 (2022-12-11)

  • b9de74b v0.1.1
  • 8b68085 chore: short output log
  • d85914b chore: comments

0.1.0 (2022-12-02)

  • 60aacb2 docs: v0.1.0
  • ee326bd feat: v0.1.0 🌱
  • a43ce4e deps: add chokidar, fast-glob
  • 7603e43 First commit