-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
123 lines (113 loc) · 2.72 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readdir } from 'node:fs/promises'
import { defineConfig } from 'rollup'
import { createRequire } from 'node:module'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import license from 'rollup-plugin-license'
import dts from 'rollup-plugin-dts'
const __dirname = dirname(fileURLToPath(import.meta.url))
const pkg = createRequire(import.meta.url)('./package.json')
const modules = await readdir(resolve(__dirname, 'lib'))
const tsPlugin = typescript({
removeComments: true,
noEmitOnError: true,
declaration: false
})
const licensePlugin = license({
banner: {
content: `
estdlib v${pkg.version}
(c) 2024-present YaXing Son and Estdlib contributors
@license MIT
`,
commentStyle: 'regular'
}
})
const absolute = path => resolve(__dirname, path)
function buildModuleOptions(moduleName) {
return {
input: absolute(`lib/${moduleName}/index.ts`),
output: [
{
file: absolute(`dist/${moduleName}/index.js`),
format: 'esm',
sourcemap: true
},
{
file: absolute(`dist/${moduleName}/index.cjs`),
format: 'cjs'
}
],
plugins: [tsPlugin]
}
}
function buildModuleDeclarationOptions(moduleName) {
return {
input: absolute(`lib/${moduleName}/index.ts`),
output: [
{
file: absolute(`dist/${moduleName}/index.d.ts`),
format: 'esm'
}
],
plugins: [dts()]
}
}
function buildLibOptions() {
return {
input: 'index.ts',
output: [
{
file: absolute('dist/index.js'),
format: 'esm',
sourcemap: true
},
{
file: absolute('dist/index.cjs'),
format: 'cjs'
},
{
file: absolute('dist/estdlib.js'),
format: 'iife',
name: 'estdlib',
plugins: [licensePlugin]
},
{
file: absolute('dist/estdlib.min.js'),
format: 'iife',
name: 'estdlib',
plugins: [
terser({
ecma: 2015,
keep_fnames: true,
compress: { sequences: false }
}),
licensePlugin
]
},
{
file: absolute('dist/estdlib.esm.js'),
format: 'esm'
}
],
plugins: [tsPlugin]
}
}
function buildLibDeclarationOptions() {
return {
input: 'index.ts',
output: {
file: absolute('dist/index.d.ts'),
format: 'esm'
},
plugins: [dts()]
}
}
export default defineConfig([
...modules.map(moduleName => buildModuleOptions(moduleName)),
...modules.map(moduleName => buildModuleDeclarationOptions(moduleName)),
buildLibOptions(),
buildLibDeclarationOptions()
])