Test esbuild to generate ESModule and CommonJS

This commit is contained in:
Guilherme Werner 2024-01-27 11:46:54 -03:00
parent 46db10fcc7
commit 4764ec2e64
6 changed files with 689 additions and 7 deletions

28
tools/esbuild.js Normal file
View file

@ -0,0 +1,28 @@
import { build } from 'esbuild'
import { nodeExternalsPlugin } from 'esbuild-node-externals'
const baseConfig = {
entryPoints: ['lib/index.js'],
platform: 'node',
target: 'node14',
bundle: true,
minify: false,
sourcemap: false,
legalComments: 'none',
plugins: [nodeExternalsPlugin()]
}
const moduleConfig = {
...baseConfig,
outfile: 'dist/index.mjs',
format: 'esm'
}
const legacyConfig = {
...baseConfig,
outfile: 'dist/index.cjs',
format: 'cjs'
}
build(moduleConfig).then(() => { }).catch(() => { process.exit(1) })
build(legacyConfig).then(() => { }).catch(() => { process.exit(1) })