forked from riccardoperra/codeimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
58 lines (51 loc) · 1.33 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
import typescript from '@rollup/plugin-typescript';
import {readdirSync, rmSync, statSync} from 'fs';
import {posix} from 'path';
import {defineConfig} from 'rollup';
import * as pkg from './package.json';
const {normalize} = posix;
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',
];
const inputs = themes.reduce((acc, theme) => {
return {
...acc,
[theme]: `src/lib/themes/${theme}/index.ts`,
};
}, {});
rmSync('dist', {
force: true,
recursive: true,
});
export default defineConfig({
input: {
index: 'src/public-api.ts',
themes: 'src/lib/themes/index.ts',
...inputs,
},
external,
plugins: [
typescript({
declarationDir: './dist',
}),
],
output: {
dir: 'dist',
format: 'es',
sourcemap: true,
preserveModules: true,
entryFileNames: source => {
const path = normalize(source.facadeModuleId).replaceAll('\\', '/');
return source.isEntry && themes.some(theme => path.includes(theme))
? 'index.js'
: `${source.name}.js`;
},
},
});