father icon indicating copy to clipboard operation
father copied to clipboard

father-build 构建产物重复导出问题

Open billfeller opened this issue 3 years ago • 1 comments

问题描述

基于 dumi 开发组件库,如果在 src 声明需要导出的对象,在内部通过 @ 别名路径引导,导致通过 father-build 构建的产物存在重复导出问题。

复现步骤

  1. 基于 dumi 初始化组件脚手架:$ npx @umijs/create-dumi-lib
  2. src 目录中新增 config.ts 文件:
    export const config = { test: 12 };
    
  3. 在 src/index.ts 导出声明:
    export { default as Foo } from './Foo';
    export * from './config';
    
  4. 在 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>
         );
       };
    
  5. 执行 npm run build ,对照 dist/index.esm.js 存在多份 config 拷贝; image

潜在的问题 引用的对象不是同一个,可能导致对象更新操作,不会触发对应更新操作,比如,这里的对象是一个 ReactContext 对象。

billfeller avatar May 21 '21 15:05 billfeller

需要通过 @rollup/plugin-alias 兼容 @ 路径别名

billfeller avatar May 21 '21 15:05 billfeller

father 4 已发布,可尝试升级到最新版:https://github.com/umijs/father/blob/master/docs/guide/migrate.md

旧版本不再维护,感谢支持

PeachScript avatar Aug 31 '22 11:08 PeachScript