esbuild-plugin-extract-helpers
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

esbuild-plugin-extract-helpers

Esbuild plugin to extract cjs helpers (like tslib)

lcov npm

Status

PoC

Problem

By default, esbuild injects helpers into each cjs module. It's fine, when you have just a few, but definitely not when there are many. This plugin extracts helpers into a separate file.

Usage

import { build, BuildOptions } from 'esbuild'
import { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'

const plugin = extractHelpersPlugin({
  cwd: 'build',         // Optional. Defaults to BuildOptions.outdir || BuildOptions.absWorkingDir
  include: /\.cjs/,     // Optional. Defaults to /./
  helper: 'esblib.cjs'  // Optional. Default value is esblib.cjs
})
const config: BuildOptions = {
  entryPoints: ['index.ts'],
  outdir: 'target/cjs',
  plugins: [plugin],
  format: 'cjs'
}

await build(config)

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i esbuild-plugin-extract-helpers

Weekly Downloads

628

Version

0.0.6

License

MIT

Unpacked Size

15.1 kB

Total Files

7

Last publish

Collaborators

  • antongolub