-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.mjs
34 lines (28 loc) · 885 Bytes
/
build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from 'node:fs';
import { build } from 'esbuild';
import packageJson from './package.json' assert { type: 'json' };
async function buildModule() {
const shared = {
entryPoints: ['source/index.ts'],
bundle: true,
minify: true,
treeShaking: true,
external: packageJson.dependencies ? Object.keys(packageJson.dependencies) : []
};
await build({
...shared,
outfile: 'bundled/commonjs/index.js',
format: 'cjs'
});
await build({
...shared,
outfile: 'bundled/esm/index.esm.js',
format: 'esm',
});
}
function generateCommonjsPackageJson() {
const packageJsonCommonJs = JSON.stringify({ ...packageJson, type: undefined }, null, 2);
fs.writeFileSync('./bundled/commonjs/package.json', packageJsonCommonJs);
}
await buildModule();
generateCommonjsPackageJson();