forked from zce/velite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
51 lines (48 loc) · 1.36 KB
/
rollup.config.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
// @ts-check
import { builtinModules } from 'node:module'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import { defineConfig } from 'rollup'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'
import pkg from './package.json' assert { type: 'json' }
const external = [...Object.keys(pkg.dependencies), ...builtinModules.flatMap(m => [m, `node:${m}`]), 'fsevents']
export default defineConfig([
{
input: ['src/index.ts', 'src/cli.ts'],
output: {
dir: 'dist',
chunkFileNames: 'velite-[hash].js'
},
external,
plugins: [
json(),
commonjs(),
nodeResolve(),
esbuild({ target: 'node18' })
]
},
{
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts'
},
external,
plugins: [
dts({ respectExternal: true }),
{
name: 'flatten-declare-module',
generateBundle: (_, bundle) => {
for (const fileName in bundle) {
const chunk = bundle[fileName]
if (chunk.type === 'chunk') {
chunk.code = chunk.code.replace(/\ndeclare module ['"].+['"] {([^]+?)\n}/g, "$1")
// (_, inner) => inner.split('\n').map(line => line.replace(/^ /, '')).join('\n')
}
}
}
}
]
}
])