esbuild-plugin-transform-ext
v0.1.0
Published
Esbuild plugin for changing file extensions in output
Downloads
3
Readme
esbuild-plugin-transform-ext
Esbuild plugin for changing file extensions in outputs
Esbuild provides some useful features for transforming file extensions: out-extension, resolve-extensions. But it lacks the ability to transform file extensions in the middle of the build process – in the bundles themselves.
Status
PoC
Usage
import { build, BuildOptions } from 'esbuild'
import { transformExtPlugin } from 'esbuild-plugin-transform-ext'
const plugin = transformExtPlugin({
cwd: 'target/mjs', // defaults to build.initialOptions.absWorkingDir || process.cwd()
rules: [
{
pattern: /\.cjs$/, // if not specified, the plugin will apply to all files
map: { // defautls to build.initialOptions.outExtension
'': '.cjs',
'.js': '.cjs',
}
},
{
pattern: /\.mjs$/,
map: {
'.js': '.mjs',
}
}
]
})
const config: BuildOptions = {
entryPoints: ['index.ts'],
outdir: 'target/cjs',
plugins: [plugin],
outExtension: { '.js': '.cjs' },
format: 'cjs'
}
await build(config)