-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor build script & update package.json, readme
- Loading branch information
Gihan Kim
committed
May 23, 2024
1 parent
cf07c4a
commit 826e248
Showing
3 changed files
with
35 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
import path from 'path'; | ||
import { build, Format } from 'esbuild'; | ||
|
||
const formats: Format[] = ['cjs', 'esm']; | ||
const filenameByFormat: Omit<Record<Format, string>, 'iife'> = { | ||
cjs: 'index.js', | ||
esm: 'index.mjs', | ||
}; | ||
|
||
(async () => { | ||
for (const format of formats) { | ||
await build({ | ||
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')], | ||
bundle: true, | ||
platform: 'node', | ||
loader: { | ||
'.ts': 'ts' | ||
}, | ||
external: ['path', 'fs', 'typescript'], | ||
outfile: path.resolve(__dirname, '..', 'build', filenameByFormat[format]), | ||
format, | ||
}).catch((e) => { | ||
console.error(e); | ||
}); | ||
} | ||
// CommonJS Build | ||
await build({ | ||
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')], | ||
bundle: true, | ||
platform: 'node', | ||
loader: { | ||
'.ts': 'ts' | ||
}, | ||
external: ['path', 'fs', 'typescript'], | ||
outfile: path.resolve(__dirname, '..', 'build', filenameByFormat['cjs']), | ||
format: 'cjs', | ||
}).catch((e) => { | ||
console.error(e); | ||
}); | ||
// ESModule Build | ||
await build({ | ||
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')], | ||
bundle: true, | ||
platform: 'node', | ||
loader: { | ||
'.ts': 'ts' | ||
}, | ||
external: ['path', 'fs', 'typescript'], | ||
outfile: path.resolve(__dirname, '..', 'build', filenameByFormat['esm']), | ||
format: 'esm', | ||
}).catch((e) => { | ||
console.error(e); | ||
}); | ||
})(); |