-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
41 lines (38 loc) · 1.15 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
import FastGlob from 'fast-glob';
import { basename, dirname } from 'node:path';
import { defineConfig, ModuleFormat } from 'rollup';
import { terser } from 'rollup-plugin-terser';
import ts from 'rollup-plugin-typescript2';
const isDev =
process.env['NODE_ENV'] === 'development' ||
process.env['ROLLUP_WATCH'] === 'true';
const extensionMap: Record<ModuleFormat, string> = {
amd: 'js',
cjs: 'cjs',
commonjs: 'cjs',
esm: 'mjs',
es: 'mjs',
iife: 'js',
module: 'mjs',
system: 'js',
systemjs: 'js',
umd: 'js',
};
const formats: ModuleFormat[] = ['cjs', 'esm'];
const submodules = FastGlob.sync(['src/*/index.{ts,tsx}'], { stats: false });
export default submodules.map(path => {
const moduleName = basename(dirname(path));
return defineConfig({
input: path,
output: formats.map(format => ({
dir: `dist/${format}`,
entryFileNames: `${moduleName}.${extensionMap[format]}`,
format,
sourcemap: isDev,
})),
plugins: [ts({ tsconfig: 'tsconfig.build.json' }), !isDev && terser()],
onwarn: (warning, defaultHandler) => {
!['EMPTY_BUNDLE'].includes(warning.code!) && defaultHandler(warning);
},
});
});