-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.mjs
More file actions
64 lines (60 loc) · 1.44 KB
/
build.mjs
File metadata and controls
64 lines (60 loc) · 1.44 KB
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
58
59
60
61
62
63
64
import esbuild from 'esbuild'
import fs from 'fs/promises'
// https://esbuild.github.io/api/#main-fields-for-package-authors
const common = {
entryPoints: ['src/index.ts'],
bundle: true,
minify: true,
loader: {
'.gql': 'text',
'.graphql': 'text',
},
}
const builds = [
esbuild.build({
...common,
entryPoints: ['src/server/index.ts'],
format: 'cjs',
platform: 'node',
target: ['node18'],
outfile: 'dist/node-cjs.js',
}),
esbuild.build({
...common,
entryPoints: ['src/server/index.ts'],
format: 'esm',
platform: 'node',
target: ['node18'],
outfile: 'dist/node-esm.js',
packages: 'external',
}),
esbuild.build({
...common,
format: 'esm',
platform: 'browser',
target: ['chrome58', 'firefox57', 'safari11', 'edge88'],
outfile: 'dist/browser-esm.js',
jsx: 'automatic',
external: ['react', 'react-dom'],
}),
esbuild.build({
...common,
format: 'cjs',
platform: 'browser',
target: ['chrome58', 'firefox57', 'safari11', 'edge88'],
outfile: 'dist/browser-cjs.js',
jsx: 'automatic',
}),
]
try {
await Promise.all(builds)
await fs.mkdir('dist', { recursive: true })
await Promise.all([
fs.copyFile('src/types/index.ts', 'dist/index.d.ts'),
fs.copyFile('src/types/graphql.d.ts', 'dist/graphql.d.ts'),
fs.copyFile('schema.json', 'dist/schema.json'),
])
} catch (err) {
console.error('Build failed:', err)
process.exit(1)
}