-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.ts
66 lines (61 loc) · 1.68 KB
/
rollup.config.ts
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
import { createRequire } from 'module'
import { resolve } from 'path'
import { fileURLToPath } from 'url'
import { type RollupOptions, defineConfig } from 'rollup'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'
import json from '@rollup/plugin-json'
import replace from '@rollup/plugin-replace'
import alias from '@rollup/plugin-alias'
import dts from 'rollup-plugin-dts'
import terser from '@rollup/plugin-terser'
const _require = createRequire(import.meta.url)
const pkg = _require('./package.json')
const ROOT = fileURLToPath(import.meta.url)
const r = (p: string) => resolve(ROOT, '..', p)
const external = [...Object.keys(pkg['dependencies'] || {})]
const plugins = [
alias({
entries: {
'readable-stream': 'stream',
},
}),
replace({
'navigator.userAgentData': 'undefined',
'navigator.userAgent': 'undefined',
preventAssignment: true,
}),
commonjs(),
nodeResolve({ preferBuiltins: false }),
esbuild({ target: 'node14' }),
json(),
terser()
]
const esmBuild: RollupOptions = {
input: r('packages/index.ts'),
output: {
format: 'esm',
entryFileNames: `[name].js`,
chunkFileNames: 'serve-[hash].js',
dir: r('dist/'),
},
external,
plugins,
onwarn(warning, warn) {
if (warning.code !== 'EVAL') warn(warning)
},
}
const typing: RollupOptions = {
input: r('packages/index.ts'),
output: {
format: 'esm',
file: 'dist/index.d.ts',
},
external,
plugins: [dts()],
}
const config = defineConfig([])
config.push(esmBuild)
config.push(typing)
export default config