-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
64 lines (55 loc) · 1.4 KB
/
build.js
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 { rollup } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { default as commonjs } from '@rollup/plugin-commonjs'
import { default as typescript } from '@rollup/plugin-typescript'
import { readFile, rename, writeFile } from 'node:fs/promises'
const plugins = [
nodeResolve({
preferBuiltins: false,
}),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
}),
]
async function build() {
const pathToSpecUrl = new URL(
'./node_modules/spec-url/src/',
import.meta.url
)
for (const pathname of ['host.js', 'index.js']) {
const pathToHostJs = new URL(pathname, pathToSpecUrl)
const dataOfHostJs = await readFile(pathToHostJs, 'utf8')
await writeFile(pathToHostJs, dataOfHostJs.replace(
/import \* as punycode from 'punycode'/g,
`import punycode from 'punycode'`
))
}
const configs = [
{
inputOptions: {
input: 'src/URI.ts',
plugins,
onwarn(warning, warn) {
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
},
},
outputOptions: {
inlineDynamicImports: true,
file: 'mod.js',
format: 'esm',
sourcemap: true,
},
},
]
for (const config of configs) {
const bundle = await rollup(config.inputOptions)
// or write the bundle to disk
await bundle.write(config.outputOptions)
// closes the bundle
await bundle.close()
// cleanup the bundle
await rename('URI.d.ts', 'mod.d.ts')
}
}
build()