-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathrollup.config.js
47 lines (43 loc) · 1.33 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
// @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' with { 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')
}
}
}
}
]
}
])