-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
103 lines (100 loc) · 2.3 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
import { dirname, relative, resolve } from 'path'
import typescript from '@rollup/plugin-typescript'
import dts from 'rollup-plugin-dts'
import { cwd } from 'process'
const dir = 'dist'
const useSrc = ({ out, ext } = {}) => ({
name: 'local:useSrc',
resolveId(source, importer) {
if (ext.some((e) => source.endsWith(e))) {
const here = cwd()
const from =
typeof out === 'string'
? out
: dirname(typeof out === 'function' ? out(importer) : importer)
const originalImporter = importer.replace(`${here}/dist`, here)
const originalImporterDir = dirname(originalImporter)
const original = resolve(originalImporterDir, source)
const relativePath = relative(from, original)
return {
id: relativePath,
external: true,
}
}
},
})
export default [
{
input: 'src/index.ts',
output: [
{
dir,
format: 'es',
},
],
plugins: [
typescript(),
useSrc({
ext: ['.astro', '.svelte', '.vue', '.scss', '.css', '.png', '.jpg'],
dir,
out: (path) => path.replace('src', 'dist'),
}),
],
},
{
input: 'src/components/index.ts',
output: [
{
file: 'dist/components.js',
format: 'es',
},
],
plugins: [
typescript(),
useSrc({
ext: ['.astro', '.vue'],
dir,
out: (path) => path.replace('src/components', 'dist'),
}),
],
},
{
input: 'src/utils/index.ts',
output: [
{
file: 'dist/utils.js',
format: 'es',
},
],
plugins: [typescript()],
},
{
input: 'dist/src/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [
dts(),
useSrc({
ext: ['.astro', '.svelte', '.vue', '.scss', '.css', '.png', '.jpg'],
dir,
out: (path) => path.replace('dist/src', 'dist'),
}),
],
},
{
input: 'dist/src/components/index.d.ts',
output: [{ file: 'components.d.ts', format: 'es' }],
plugins: [
dts(),
useSrc({
ext: ['.astro', '.vue'],
dir,
out: (path) => path.replace('dist/src/components', ''),
}),
],
},
{
input: 'dist/src/utils/index.d.ts',
output: [{ file: 'utils.d.ts', format: 'es' }],
plugins: [dts()],
},
]