-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
rollup.config.js
78 lines (69 loc) · 1.87 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
import typescript from '@rollup/plugin-typescript';
import {readdirSync, rmSync, statSync} from 'node:fs';
import {posix} from 'node:path';
import {defineConfig} from 'rollup';
// eslint-disable-next-line prettier/prettier
import * as pkg from './package.json' with {type: 'json'};
const {normalize} = posix
const __dirname = import.meta.dirname;
const themesPath = posix.join(__dirname, 'src/lib/themes');
const themes = readdirSync(themesPath).filter(file =>
statSync(posix.join(themesPath, file)).isDirectory(),
);
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
'@primer/primitives/dist/ts/colors/dark',
'@primer/primitives/dist/ts/colors/light',
'@primer/primitives/dist/ts/colors/dark_dimmed',
];
const inputs = themes.reduce((acc, theme) => {
return {
...acc,
[theme]: `src/lib/themes/${theme}/index.ts`,
};
}, {});
rmSync('dist', {
force: true,
recursive: true,
});
const bundleInput = {
index: 'src/public-api.ts',
themes: 'src/lib/themes/index.ts',
...inputs,
}
export default defineConfig({
input: bundleInput,
external,
plugins: [
typescript({
declarationDir: './dist',
}),
],
output: {
dir: 'dist',
format: 'es',
sourcemap: true,
preserveModules: true,
entryFileNames: source => {
const path = normalize(source.facadeModuleId).replaceAll('\\', '/');
if (source.isEntry) {
if (source.name === 'index') {
return '[name].js';
}
const theme = themes.find(_ => path.includes(`lib/themes/${_}`));
if (theme) {
return `lib/themes/${theme}/index.js`
} else {
const path = bundleInput[source.name];
if (path) {
return path
.replace('src/', '')
.replace('.ts', '.js');
}
}
}
return "[name].js";
},
},
});