generated from totto2727/esm-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mts
57 lines (52 loc) · 1.4 KB
/
build.mts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as esbuild from 'esbuild';
const targetBasePath = `${import.meta.dir ?? '.'}/src`;
const distBasePath = `${import.meta.dir ?? '.'}/dist`;
// ベースディレクトリからのパス(拡張子は除く)
const files = ['index'];
function entrypoints(files: string[], extension: 'ts' | 'mts' | 'cts') {
return files.map((v) => `${targetBasePath}/${v}.${extension}`);
}
const esms = entrypoints(files, 'mts');
const cjss = entrypoints(files, 'cts');
await Promise.all([
// Bun.build({
// entrypoints: esms,
// outdir: `${distBasePath}/import`,
// target: "node",
// format: "esm",
// splitting: true,
// minify: true,
// naming: "[dir]/[name].m[ext]",
// })
// .then(console.info)
// .catch(console.error),
esbuild
.build({
entryPoints: esms,
bundle: true,
minify: true,
splitting: true,
outdir: `${distBasePath}/import`,
platform: 'neutral',
format: 'esm',
target: 'esnext',
outExtension: { '.js': '.mjs' },
external: ['ws'],
})
.then(console.info)
.catch(console.error),
esbuild
.build({
entryPoints: cjss,
bundle: true,
minify: true,
outdir: `${distBasePath}/require`,
platform: 'node',
format: 'cjs',
target: 'esnext',
outExtension: { '.js': '.cjs' },
external: ['ws'],
})
.then(console.info)
.catch(console.error),
]);