Skip to content

use babel to transpile ts codes to es5 excluding plugins causing perf issue #2415

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

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

fuzhenn
Copy link
Member

@fuzhenn fuzhenn commented Sep 5, 2024

该pr是 #2398 的进一步补充。
通过对babel的配置,取消对解构,参数数组等语法的编译,来解决 #2398 中尝试解决的性能问题。

主要包括两个步骤:

  • tsconfig 中将编译目标改为es6
  • 改用babel将es6语法编译为es5
  • 在babel中禁用对destructuring,spread,parameters等语法转换

进一步思考:
也许核心库只需要少数几个关键的编译选项,例如class编译为函数,就能让插件正常工作,这样能尽量避免编译产生的性能问题,减少代码体积,也能提高编译速度。

@deyihu
Copy link
Collaborator

deyihu commented Sep 5, 2024

@fuzhenn 确实可以这么干,但是有个问题需要注意

  • ...是个比较新的语法(我记得不是es2015,哪个版本的我不记得了),源码里用了不少这个语法,当babel忽略其时,可能导致一些内核老的浏览器不支持该语法,例如360浏览器啥的,一般chrome和edge都是自动升级的没有这个问题
  • tsc 还是保留.js文件比较好
  • npm 包应该发布 dist里的所有东西,方便用户进行模块化使用
import Eventable from 'maptalks/dist/core/Eventable'

@fuzhenn
Copy link
Member Author

fuzhenn commented Sep 5, 2024

@fuzhenn 确实可以这么干,但是有个问题需要注意

  • ...是个比较新的语法(反正不是es2015,哪个版本的我不记得了),源码里用了不少这个语法,当babel忽略其时,可能导致一些内核老的浏览器不支持该语法,例如360浏览器啥的,一般chrome和edge都是自动升级的没有这个问题
  • tsc 还是保留.js文件比较好
  • npm 包应该发布 dist里的所有东西,方便用户进行模块化使用
import Eventable from 'maptalks/dist/core/Eventable'

...(spread)在数组和参数中使用,都是es2015的语法,应该可以放心用,不会有兼容性问题:

@fuzhenn fuzhenn merged commit 0ca28ec into master Sep 5, 2024
1 check passed
@fuzhenn fuzhenn deleted the babel branch September 5, 2024 09:55
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

Successfully merging this pull request may close these issues.

2 participants