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

支持esm打包 #3908

Closed
iceqing opened this issue Mar 30, 2022 · 3 comments
Closed

支持esm打包 #3908

iceqing opened this issue Mar 30, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@iceqing
Copy link
Contributor

iceqing commented Mar 30, 2022

是否关联于某个问题吗:

由于Webpack开发编译相对较慢,想用Vite支持amisreact-amis-admin )。

但是由于amis未提供ems版本编译包,导致部分功能会报错,比如iceqing/react-amis-admin#3

Uncaught (in promise) Error: Dynamic require of "echarts" is not supported
    at chunk-ACCAMVX6.js?v=64adb3e9:12:9
    at Chart.js:106:91
    at new Promise (<anonymous>)
    at Chart.js:106:61
    at async Promise.all (index 0)

该报错示例代码可参考react-amis-admin vite分支

预期的解决方案:

类似于redux分别提供cjsesm的包,
或者lodash-es等,提供单独的esm依赖。

其他可接受方案:

提供amis的vite示例

任何附加信息:

vite 使用ESM 作为模块化方案,因此不支持使用require 方式来导入模块,我尝试过对于一般的require做转换为import使用(使用vite-plugin-commonjs插件),但是对于这种Dynamic require of "echarts"仍然支持不够好,期望官方能提供esm的包支持。

@iceqing iceqing added the enhancement New feature or request label Mar 30, 2022
@agileago
Copy link
Contributor

agileago commented Apr 2, 2022

其实你用上vite后,会发现编译其实也就那样,我现在就是用的vite编译amis的,没有想象中那么美好

@iceqing
Copy link
Contributor Author

iceqing commented Jul 17, 2022

目前amis 2.0已经支持了esm,amis开发同学辛苦了,暂时关闭该问题

@iceqing iceqing closed this as completed Jul 17, 2022
@iceqing
Copy link
Contributor Author

iceqing commented Jul 17, 2022

@agileago 我利用webpack和vite测试了下,编译生产包的耗时几乎差距不大。

但是本地热加载差距非常大,webpack热加载开启HMR基本每次刷新在2到3秒之间,vite几乎是瞬间(0.5s内),可以大幅减少开发时的不必要等待,如果是对热加载时间有追求,vite值得尝试下。

我在github创建了一个示例项目可以参考(测试的分支分别是vite3分支和webpack分支):
https://github.com/iceqing/react-amis-admin

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

No branches or pull requests

2 participants