npx esbuild --outdir=build --platform=node --format=cjs src/*.ts
npx esbuild --out-extension:.js=.mjs --outdir=build --platform=node --format=esm src/*.ts
#!/usr/bin/env node
import esbuild from 'esbuild';
const commonOptions = {
// https://esbuild.github.io/api/
entryPoints: ['src/main.js'],
bundle: true,
platform: 'node',
minify: true,
outdir: 'dist'
}
esbuild
.build({
...commonOptions,
format: 'esm',
outExtension: { '.js': '.mjs' }
})
.catch(() => process.exit(1))
esbuild
.build({
...commonOptions,
format: 'cjs',
outExtension: { '.js': '.cjs' }
})
.catch(() => process.exit(1))
package.json
"main": "./build/index.js",
"module": "./build/index.mjs",
"typings": "./build/index.d.ts",
참고)