esbuild-plugin-extract-helpers
v0.0.6
Published
Esbuild plugin to extract cjs helpers (like tslib)
Downloads
2,142
Readme
esbuild-plugin-extract-helpers
Esbuild plugin to extract cjs helpers (like tslib)
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)