在 CRA Monorepo 中摇树

问题描述

我有一个 monorepo yarn 工作区项目,其中包含一个 create-react-app 应用程序和一个 UI 库。

在我的 @app/ui 包中的 src 文件夹中,我有以下文件

country.ts

interface Country {
  name: string;
  alpha2: string;
  alpha3: string;
  subregion: string;
}

export const countries: Record<string,Country> = {
  NZ: {
    name: 'New Zealand',alpha2: 'NZ',alpha3: 'NZL',subregion: 'Australia and New Zealand'
  },};

index.ts

export * from countries.ts;

...以及从上面的 index.ts 导出的其他文件。即使我的 @app/cra 应用程序将 @app/ui 作为依赖项,并且在其中一个文件中包含以下代码行:

import { MyComponent } from @app/ui

我从来没有真正从 countries.ts 导入任何东西。我使用 craco 通过覆盖配置以包含使用 react-scripts 的外部文件夹,从而能够在 CRA 的 babel-loader 构建中包含外部 UI 包。

但是,当我为生产构建 CRA 应用程序并使用源映射分析器检查构建生成的包时,我总是在其中找到 countries。为什么不摇树?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)