-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
rollup.common.ts
66 lines (59 loc) · 1.57 KB
/
rollup.common.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
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
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { RollupOptions, OutputOptions, ModuleFormat } from 'rollup';
//@ts-ignore
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
export const commonConfig = {
watch: {
clearScreen: false,
},
treeshake: 'smallest',
} as const satisfies RollupOptions;
export const commonPlugins = [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
include: ['../../**'],
preventAssignment: true,
}),
];
export const packageOutput = (
name: string,
env: 'production' | 'development' | undefined,
format: ModuleFormat,
ext: string,
variants: ('min' | 'normal')[]
) => {
const targets: OutputOptions[] = [];
if (variants.includes('normal')) {
targets.push({
name: `@tolgee/${name}`,
entryFileNames: `tolgee-${name}${env ? `.${env}` : ''}.${format}.${ext}`,
format,
});
}
if (variants.includes('min')) {
targets.push({
name: `@tolgee/${name}`,
entryFileNames: `tolgee-${name}${
env ? `.${env}` : ''
}.${format}.min.${ext}`,
format,
plugins: [terser()],
});
}
return targets;
};
type Props = {
name: string;
env?: 'development' | 'production';
min?: boolean;
};
export const buildPackage = ({ name, env }: Props): RollupOptions => ({
...commonConfig,
output: [
...packageOutput(name, env, 'esm', 'js', ['min', 'normal']),
...packageOutput(name, env, 'umd', 'js', ['min']),
...packageOutput(name, env, 'umd', 'cjs', ['normal']),
],
plugins: commonPlugins,
});