-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
49 lines (46 loc) · 1.34 KB
/
Copy pathrollup.config.mjs
File metadata and controls
49 lines (46 loc) · 1.34 KB
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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import pkg from './package.json' with { type: 'json' };
// 运行时依赖与 peer 依赖一律外置:由使用方 npm 安装,不打进产物,
// 避免依赖被重复打包(此前 @emotion/css、clsx 被内联到 dist/node_modules 下)。
const externalDeps = [
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
'react/jsx-runtime',
];
const isExternal = (id) => externalDeps.some((dep) => id === dep || id.startsWith(`${dep}/`));
/** @type {import('rollup').RollupOptions} */
export default {
input: 'src/index.ts',
output: [
{
dir: 'dist/esm',
format: 'esm',
sourcemap: false,
preserveModules: true,
preserveModulesRoot: 'src',
exports: 'named',
},
{
dir: 'dist/cjs',
format: 'cjs',
sourcemap: false,
preserveModules: true,
preserveModulesRoot: 'src',
exports: 'named',
},
],
plugins: [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
exclude: ['stories/**', '**/*.stories.tsx'],
}),
],
external: isExternal,
};