Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build-scripts 会把 import { ConfigProvider } from '@alifd/next' 吃掉 #4951

Closed
guoyunhe opened this issue Nov 19, 2021 · 2 comments
Closed
Assignees

Comments

@guoyunhe
Copy link
Contributor

What is the current behavior? 发生了什么?

在 build-scripts 配置的组件库项目中,源码中 import { ConfigProvider } from '@alifd/next';

image

然后构建,在 lib 和 es 输出中,ConfigProvider 的导入都丢失了,其他导入正常。在应用中引用这个包报错。

What is the expected behavior? 期望的结果是什么?

ConfigProvider 编译后能被正常导入

Any additional comments? 相关环境信息?

  • ice.js Version:build-scripts 0.1.32
  • build.json Configuration
{
  "plugins": [
    "build-plugin-component",
    [
      "build-plugin-moment-locales",
      {
        "locales": ["zh-cn"]
      }
    ]
  ],
  "library": "BcOtFetch",
  "libraryTarget": "umd",
  "filename": "index",
  "minify": true,
  "externals": {
    "react": "React",
    "react-dom": "ReactDOM",
    "@alifd/next": "Next",
    "moment": "moment"
  }
}
  • Node Version:
  • Platform:
@guoyunhe
Copy link
Contributor Author

这个 ConfigProvider 我们并没有当 React 组件来使用,而是当作类来使用它的一些静态方法/变量。我尝试手动加了一行 JSX

image

import 就回来了。看来是 build-scripts 用了什么算法,只导入 JSX?

@maoxiaoke
Copy link
Collaborator

经分析,代码中 ConfigProvider 的用法如下:

import { ConfigProvider } from '@alifd/next';

(ConfigProvider as any).getLanguage();

babel-plugin-import 不会处理 typescript as 语法,从而无法未能正确处理 ConfigProvider 的按需逻辑。相关 issue

解决方案

  1. 不使用 as 语法
  2. 未来组件开发不推荐使用 babel-plugin-import 来按需加载组件(直接使用 tree-shaking 能力),因此建议开启 disableGenerateStyle: true 相关讨论 [RFC] 重新 Review 业务组件自动生成 style.js 以及项目中自动引入该文件的功能设计 #4705

这个问题暂时不再跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants