-
Notifications
You must be signed in to change notification settings - Fork 33
/
rollup.config.mjs
89 lines (85 loc) · 2.2 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
87
88
89
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import external from 'rollup-plugin-peer-deps-external';
import { dts } from 'rollup-plugin-dts';
import tsPaths from 'rollup-plugin-tsconfig-paths';
import preserveDirectives from 'rollup-plugin-preserve-directives';
import tsBuildConfig from './bundle-base.tsconfig.json' assert { type: 'json' };
import packageJson from './package.json' assert { type: 'json' };
// suppresses warnings printed to console as part of bundling components with directives present.
const onWarnSuppression = {
onwarn(warning, warn) {
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes(`"use client"`)) {
return;
}
warn(warning);
},
};
const commonPlugins = [external(), tsPaths(), resolve(), commonjs()];
export default [
// cjs export
{
input: 'src/index.ts',
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: true,
},
],
plugins: [
...commonPlugins,
typescript({
tsconfig: 'bundle-base.tsconfig.json',
compilerOptions: {
declaration: false,
},
}),
terser(),
],
...onWarnSuppression,
},
// esm export
{
input: 'src/index.ts',
output: [
{
dir: packageJson.module,
format: 'esm',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src',
},
],
plugins: [
...commonPlugins,
typescript({
tsconfig: 'bundle-base.tsconfig.json',
compilerOptions: {
declaration: true,
declarationDir: 'dist/esm',
emitDeclarationOnly: true,
outDir: 'dist/esm',
},
}),
preserveDirectives(),
terser({ compress: { directives: false } }),
],
...onWarnSuppression,
},
// type bundling
{
input: 'src/index.ts',
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
external: [],
plugins: [
dts({
compilerOptions: {
paths: tsBuildConfig.compilerOptions.paths,
},
}),
],
},
];