-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrollup.config.mts
More file actions
60 lines (58 loc) · 1.69 KB
/
rollup.config.mts
File metadata and controls
60 lines (58 loc) · 1.69 KB
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
import fs from 'fs'
import { builtinModules } from 'module'
import { defineConfig } from 'rollup'
import { dts } from 'rollup-plugin-dts'
import { swc } from 'rollup-plugin-swc3'
import analyzer, { adapter } from 'vite-bundle-analyzer'
const external = [...builtinModules]
export default defineConfig([
{
input: {
index: 'src/index.ts',
plugin: 'src/plugins/index.ts'
},
external,
output: [
{ dir: 'dist', format: 'esm', exports: 'named', entryFileNames: '[name].mjs', chunkFileNames: '[name]-[hash].mjs' },
{ dir: 'dist', format: 'cjs', exports: 'named', entryFileNames: '[name].js' }
],
plugins: [swc(), adapter(analyzer({ enabled: !!process.env.ANALYZE }))]
},
{
input: {
index: 'src/index.ts',
plugin: 'src/plugins/index.ts'
},
external,
output: [
{ dir: 'dist', format: 'esm', entryFileNames: '[name].d.mts' },
{ dir: 'dist', format: 'cjs', entryFileNames: '[name].d.ts' }
],
plugins: [
dts({
respectExternal: true,
compilerOptions: {
composite: true,
preserveSymlinks: false
}
}),
{
name: 'copy-global-dts',
generateBundle(_, bundle) {
for (const file in bundle) {
if (file.endsWith('.d.ts')) {
const mod = bundle[file]
if (mod.type === 'chunk') {
const pattern = /(\w+)-!~\{(\d+)\}~\.d\.ts$/
if (pattern.test(mod.preliminaryFileName)) {
const content = fs.readFileSync('./global.d.ts', 'utf-8')
mod.code = content + '\n' + mod.code
}
}
}
}
}
}
]
}
])