generated from dev-protocol/template-repos-ts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.mjs
86 lines (83 loc) · 1.86 KB
/
rollup.config.mjs
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
import dts from 'rollup-plugin-dts'
import commonjs from '@rollup/plugin-commonjs'
import { dirname, relative, resolve } from 'path'
import { cwd } from 'process'
const majorCoreAPIs = [
'dist/src/layouts/index.js',
'dist/src/images/index.js',
'dist/src/connection/index.js',
'dist/src/styles/index.js',
'dist/src/redis/index.js',
'dist/src/tailwind/index.js',
]
export const useSrc = ({ out, ext } = {}) => ({
name: 'astro',
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 [
...majorCoreAPIs.map((input) => ({
input,
output: [
{
file: input.replace('.js', '.mjs'),
format: 'es',
},
{
file: input.replace('.js', '.cjs'),
format: 'cjs',
},
],
plugins: [commonjs(), useSrc({ ext: ['.astro', '.scss', '.css', '.svg'] })],
})),
{
input: 'dist/src/index.js',
output: [
{
file: 'dist/index.mjs',
format: 'es',
},
{
file: 'dist/index.cjs',
format: 'cjs',
},
],
plugins: [commonjs()],
},
{
input: 'dist/src/index.d.ts',
output: [{ file: 'dist/clubs-core.d.ts', format: 'es' }],
plugins: [dts()],
},
...majorCoreAPIs.map((input) => ({
input: input.replace('.js', '.d.ts'),
output: [
{
file: input
.replace('.js', '.d.ts')
.replace('dist/src/', '')
.replace('/index', ''),
format: 'es',
},
],
plugins: [
dts(),
useSrc({ out: cwd(), ext: ['.astro', '.scss', '.css', '.svg'] }),
],
})),
]