/mkbuild

🚧 An esbuild based file-to-file transformer and bundler

Primary LanguageTypeScriptBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

mkbuild

github release npm codecov module type: esm license conventional commits typescript vitest yarn

An esbuild based file-to-file transformer and bundler.

Contents

Features

📦 optimized bundler and transpiler

fast and minimal builds with esbuild (integrates with the build api for plugin support — say toodles 👋🏾 to transform api hacks! 😉)

📁 bundleless dists

create bundleless distributions with file-to-file transpilation and static asset copying

😌 esm friendly

create es modules + add file extensions to specifiers in modules and declaration files

📑 dts generation (.d.cts, .d.mts, .d.ts)

generate declarations for .cjs, .cts, .js, .jsx, .mjs, .mts, .ts, and .tsx files

🧬 path alias support

resolve path aliases in .cjs, .cts, .d.cts, .d.mts, .d.ts, .js, .jsx, .mjs, .mts, .ts, and .tsx files

Install

This package is ESM only.

yarn add -D @flex-development/mkbuild esbuild typescript

From Git:

yarn add -D @flex-development/mkbuild@flex-development/mkbuild esbuild typescript
See Git - Protocols | Yarn  for details on requesting a specific branch, commit, or tag.

Use

mkbuild

Running the command above without a build configuration file will create a bundleless esm build with declarations.

Files within the src directory will be transpiled or copied and output to dist/**.{d.mts,mjs}. Declaration files, dist/**.d.mts, will be generated if typescript is installed. The original folder structure and extensions of copied files will remain in tact.

Configuration

Create build.config.{cjs,cts,js,json,mjs,mts,ts}:

/**
 * @file Build Config
 * @module config/build
 */

import { defineBuildConfig } from '@flex-development/mkbuild'

export default defineBuildConfig({
  // esbuild options; see https://esbuild.github.io/api/#build-api
  sourcemap: 'external',
  sourcesContent: false,
  treeShaking: true,
  tsconfig: 'tsconfig.build.json'
})

See all configuration options here.

Options common to build configs and build entries can be seen here.

Configuring Build Entries

/**
 * @file Build Config
 * @module config/build
 */

import { defineBuildConfig } from '@flex-development/mkbuild'
import pkg from './package.json' assert { type: 'json' }

export default defineBuildConfig({
  entries: [
    { dts: true, ignore: ['cli.ts'] }, // dist/**.{d.mts,mjs}
    { dts: true, ext: '.cjs', format: 'cjs', ignore: ['cli.ts'] }, // dist/**.{cjs,d.cts}
    { dts: 'only', ext: '.js', ignore: ['cli.ts'] }, // dist/**.d.ts
    { bundle: true, minify: true, source: 'src/cli.ts' } // dist/cli.mjs
  ],
  platform: 'node',
  sourcemap: 'external',
  sourcesContent: false,
  target: 'node' + pkg.engines.node.replace(/^\D+/, ''),
  treeShaking: true,
  tsconfig: 'tsconfig.build.json'
})

See all build entry options here.

Types

This package is fully typed with TypeScript.

Contribute

See CONTRIBUTING.md.