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

【小程序】在新版微信开发者工具下是否可以让开发者定制babel preset: {env}的使用与否 #4086

Closed
moonreplace opened this issue Aug 6, 2019 · 4 comments

Comments

@moonreplace
Copy link

moonreplace commented Aug 6, 2019

现在最新版小程序微信开发者工具1.02.1907160, 支持增强编译功能
https://developers.weixin.qq.com/community/develop/doc/000c8abaa7c6b074f4e87321756401

特性 原有逻辑 增强编译
Babel版本 babel6 babel7
Presets es2015、stage0 env {chrome:53, ios:8}
Helpers 单文件内联 跨文件共享
Async/Await 不支持 支持
严格模式开关 不支持 支持
忽略文件目录 不支持 支持
代码压缩 uglify-js terser
Babel插件 - 一系列proposal*
polyfill 大部分es6 新增三个polyfill*

使用preset-env,支持最新的ECMAScript语法

共享helpers函数,默认放在项目@babel/runtime目录,可通过项目配置文件配置

支持async/await语法,按需注入regeneratorRuntime,目录位置与helpers函数一致

文件首行是// use strict disable;时,即可禁用文件严格模式

可通过项目配置文件指定任意文件、目录不经过编译(如:miniprogram_npm)

原有逻辑是支持stage0语法的,为了向前兼容,引入了一系列proposal插件

关于polyfill,基础库中已经引入了大量的es6相关的polyfill 可参考文档,增强编译下,新增:Array.prototype.includes(es7)、Object.entries(es8)、Object.values(es8)

我们的在走编译的时候会强行走presets: 'env', 导致无法用到上述增强编译带来的便利性

  presets: [
    'env'
  ],

期望行为
babel preset env是否开启

@taro-bot
Copy link

taro-bot bot commented Aug 6, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam
Copy link
Member

Taro 的 babel 配置是用户可以自己配制的,另外使用 Taro 的话,不建议再开启小程序开发者工具的 es 编译,通过配置相关 babel 插件,可以达到相应目的

@moonreplace
Copy link
Author

moonreplace commented Aug 6, 2019

Taro 的 babel 配置是用户可以自己配制的,另外使用 Taro 的话,不建议再开启小程序开发者工具的 es 编译,通过配置相关 babel 插件,可以达到相应目的

因为我们的taro是用的babel6来做的,我们的helpers会打进每个文件。如果我们引用transform-runtime,来做的话,又会把不需要的core-js引进进来。
另外,小程序的编译的时候,我们是无法做到preset: env给去掉的。
小程序开会工具的增强编译可以把我们的helpers放到最外面,假设我们存在多个子包的情况下,会节省很多

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 2, 2020

Taro 3 已升级 babel 7,也可以配置是否使用 preset env。

@Chen-jj Chen-jj closed this as completed Jul 2, 2020
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

3 participants