father
father copied to clipboard
father-build 构建产物重复导出问题
问题描述
基于 dumi 开发组件库,如果在 src 声明需要导出的对象,在内部通过 @ 别名路径引导,导致通过 father-build 构建的产物存在重复导出问题。
复现步骤
- 基于 dumi 初始化组件脚手架:
$ npx @umijs/create-dumi-lib
- src 目录中新增 config.ts 文件:
export const config = { test: 12 };
- 在 src/index.ts 导出声明:
export { default as Foo } from './Foo'; export * from './config';
- 在 src/Foo/index.ts 中通过 @/ 引入 config.ts 文件:
import React from 'react'; import { config } from '@/config'; export default ({ title }: { title: string }) => { return ( <h1> {title} {config.test} </h1> ); };
- 执行 npm run build ,对照 dist/index.esm.js 存在多份 config 拷贝;
潜在的问题 引用的对象不是同一个,可能导致对象更新操作,不会触发对应更新操作,比如,这里的对象是一个 ReactContext 对象。
需要通过 @rollup/plugin-alias 兼容 @ 路径别名
father 4 已发布,可尝试升级到最新版:https://github.com/umijs/father/blob/master/docs/guide/migrate.md
旧版本不再维护,感谢支持