-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.mjs
99 lines (96 loc) · 2.81 KB
/
esbuild.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import * as esbuild from 'esbuild'
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals'
import JbrowseGlobals from '@jbrowse/core/ReExports/list.js'
import prettyBytes from 'pretty-bytes'
function createGlobalMap(jbrowseGlobals) {
const globalMap = {}
for (const global of [...jbrowseGlobals, 'react-dom/client']) {
globalMap[global] = {
varName: `JBrowseExports["${global}"]`,
type: 'cjs',
}
}
return globalMap
}
if (process.env.NODE_ENV === 'production') {
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
globalName: 'JBrowsePluginProtein3d',
sourcemap: true,
outfile: 'dist/jbrowse-plugin-protein3d.umd.production.min.js',
metafile: true,
minify: true,
plugins: [
globalExternals(createGlobalMap(JbrowseGlobals.default)),
{
name: 'rebuild-log',
setup({ onStart, onEnd }) {
let time
onStart(() => {
time = Date.now()
})
onEnd(({ metafile, errors, warnings }) => {
console.log(
`Built in ${Date.now() - time} ms with ${
errors.length
} error(s) and ${warnings.length} warning(s)`,
)
if (!metafile) {
return
}
const { outputs } = metafile
for (const [file, metadata] of Object.entries(outputs)) {
const size = prettyBytes(metadata.bytes)
console.log(`Wrote ${size} to ${file}`)
}
})
},
},
],
})
} else {
let ctx = await esbuild.context({
entryPoints: ['src/index.ts'],
bundle: true,
globalName: 'JBrowsePluginProtein3d',
outfile: 'dist/out.js',
metafile: true,
plugins: [
globalExternals(createGlobalMap(JbrowseGlobals.default)),
{
name: 'rebuild-log',
setup({ onStart, onEnd }) {
let time
onStart(() => {
time = Date.now()
})
onEnd(({ metafile, errors, warnings }) => {
console.log(
`Built in ${Date.now() - time} ms with ${
errors.length
} error(s) and ${warnings.length} warning(s)`,
)
if (!metafile) {
return
}
const { outputs } = metafile
for (const [file, metadata] of Object.entries(outputs)) {
const size = prettyBytes(metadata.bytes)
console.log(`Wrote ${size} to ${file}`)
}
})
},
},
],
})
let { host, port } = await ctx.serve({
servedir: '.',
port: 9001,
host: 'localhost',
})
const formattedHost = host === '127.0.0.1' ? 'localhost' : host
console.log(`Serving at http://${formattedHost}:${port}`)
await ctx.watch()
console.log('Watching files...')
}