fix(build): 修正 peerDependencies 语法及外部依赖处理

- 修改 package.json 中 peerDependencies 的版本范围语法,去除多余的 ^ 符号
- rollup.config.js 中增加 peerDependencies 到外部依赖列表,确保不打包这些依赖
- 保证组件库依赖和消费者依赖均正确处理,防止版本冲突和重复打包
- 优化构建配置,减少最终 bundle 体积
1.0
LiuJiaNan 2026-08-22 19:06:41 +08:00
parent 0dfc6e6d68
commit 7dc8d38635
2 changed files with 7 additions and 5 deletions

View File

@ -64,10 +64,10 @@
"typescript": "^5.9.3" "typescript": "^5.9.3"
}, },
"peerDependencies": { "peerDependencies": {
"@ahooksjs/use-url-state": ">=^3.5.1 <4", "@ahooksjs/use-url-state": ">=3.5.1 <4",
"@ant-design/icons": ">=5.6.1 <6", "@ant-design/icons": ">=5.6.1 <6",
"@ant-design/pro-components": ">=2.8.10 <3", "@ant-design/pro-components": ">=2.8.10 <3",
"ahooks": ">=^3.9.5 <4", "ahooks": ">=3.9.5 <4",
"antd": ">=5.27.6 <6", "antd": ">=5.27.6 <6",
"react": ">=18.3.1 <19" "react": ">=18.3.1 <19"
} }

View File

@ -289,9 +289,11 @@ const external = (id) => {
} }
// 4. npm 依赖包标记为外部 -> 不打包到 bundle 中 // 4. npm 依赖包标记为外部 -> 不打包到 bundle 中
// 原因:减少 bundle 体积,避免版本冲突,让消费者项目自己管理依赖 // dependencies 由组件库安装peerDependencies 由消费者提供,两者都应保留 import。
// 从 package.json 的 dependencies 中读取依赖列表 const dependencies = [
const dependencies = Object.keys(pkg.dependencies || {}); ...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
return dependencies.some(dep => id === dep || id.startsWith(dep + '/')); return dependencies.some(dep => id === dep || id.startsWith(dep + '/'));
}; };