generated from antfu/starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
127 lines (110 loc) · 2.7 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
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
124
125
126
127
import { resolve } from 'node:path'
import type { OutputOptions, RollupOptions } from 'rollup'
import type { Options as ESBuildOptions } from 'rollup-plugin-esbuild'
import esbuild from 'rollup-plugin-esbuild'
import json from '@rollup/plugin-json'
import dts from 'rollup-plugin-dts'
import fg from 'fast-glob'
import { packages } from './packages/metadata/packages'
const configs: RollupOptions[] = []
const pluginEsbuild = esbuild()
const pluginDts = dts()
const externals = [
'vue',
'@zuks/core',
'@zuks/metadata',
'@vueuse/core',
'lodash-es',
]
function esbuildMinifer(options: ESBuildOptions) {
const { renderChunk } = esbuild(options)
return {
name: 'esbuild-minifer',
renderChunk,
}
}
for (const { name, globals, submodules, iife, build, cjs, mjs, dts, target, external } of packages) {
if (build === false)
continue
const iifeGlobals = {
'vue': 'Vue',
'@zuks/core': 'Zuks',
'@vueuse/core': 'VueUse',
'lodash-es': '_',
...globals,
}
const iifeName = 'Zuks'
const functionNames = ['index']
if (submodules)
functionNames.push(...fg.globSync('*/index.ts', { cwd: resolve(`packages/${name}`) }).map(i => i.split('/')[0]))
for (const fn of functionNames) {
const input = fn === 'index'
? `packages/${name}/index.ts`
: `packages/${name}/${fn}/index.ts`
const output: OutputOptions[] = []
if (mjs !== false) {
output.push({
file: `packages/${name}/dist/${fn}.mjs`,
format: 'es',
})
}
if (cjs !== false) {
output.push({
file: `packages/${name}/dist/${fn}.cjs`,
format: 'cjs',
})
}
if (iife !== false) {
output.push(
{
file: `packages/${name}/dist/${fn}.iife.js`,
format: 'iife',
name: iifeName,
extend: true,
globals: iifeGlobals,
},
{
file: `packages/${name}/dist/${fn}.iife.min.js`,
format: 'iife',
name: iifeName,
extend: true,
globals: iifeGlobals,
plugins: [
esbuildMinifer({
minify: true,
}),
],
},
)
}
configs.push({
input,
output,
plugins: [
target ? esbuild({ target }) : pluginEsbuild,
json(),
],
external: [
...externals,
...(external || []),
],
})
if (dts !== false) {
configs.push({
input,
output: {
file: `packages/${name}/dist/${fn}.d.ts`,
format: 'es',
},
plugins: [
pluginDts,
],
external: [
...externals,
...(external || []),
],
})
}
}
}
export default configs