7.29.0 发布:最后一个 Babel 7 小版本
Babel 7.29.0 发布啦!
🌐 Babel 7.29.0 is out!
这是 Babel 7 的最后一个小版本,因为我们正准备发布 Babel 8.0.0。Babel 8.0.0-rc 今天也发布了:快去试试吧!
🌐 This is the last minor release of Babel 7, as we are getting ready to release Babel 8.0.0. Babel 8.0.0-rc is also out today: go try it out!
这个版本增加了通过在 <script> 元素上使用 data-target 属性来定义 @babel/standalone 的转译目标的支持。它还为 @babel/standalone 增加了对 @babel/core 异步 API 的支持。
🌐 This release include support for defining transpilation targets in @babel/standalone through a data-target attribute on <script> elements. It also adds support for the @babel/core async API to @babel/standalone.
这两项改动都是为了让从 Babel 7 迁移到 Babel 8 更加轻松。
🌐 Both of these changes are meant to ease the migration from Babel 7 to Babel 8.
你可以在 GitHub 上阅读完整的更新日志。如果你已经在使用 Babel 8 测试版,所有 7.28.0 的新功能都包含在 v8.0.0-rc.1 中。
🌐 You can read the whole changelog on GitHub. If you are already using Babel 8 beta, all the new 7.28.0 features are included in v8.0.0-rc.1.
如果你或者你的公司想支持 Babel 和 JavaScript 的发展,但不确定如何做,你可以在我们的 Open Collective 上捐助我们,更棒的是,直接与我们一起参与 新的 ECMAScript 提案 的实现!作为一个志愿者驱动的项目,我们依靠社区的支持来资助我们为广大 JavaScript 用户提供帮助。如果你想进一步讨论,欢迎联系 team@babeljs.io!
🌐 If you or your company want to support Babel and the evolution of JavaScript but aren't sure how, you can donate to us on our Open Collective and, better yet, work with us on the implementation of new ECMAScript proposals directly! As a volunteer-driven project, we rely on the community's support to fund our efforts in supporting the wide range of JavaScript users. Reach out at team@babeljs.io if you'd like to discuss more!
亮点
🌐 Highlights
@babel/standalone 对 data-targets 属性的支持 (#17482)
🌐 @babel/standalone support for data-targets attribute (#17482)
默认情况下,@babel/preset-env 会将你的代码一直转换到 ES5。在 Babel 8 中,这一默认行为将改变,它将默认使用 Browserslist 的 defaults 查询。
🌐 By default @babel/preset-env transforms your code all the way down to ES5. This is changing in Babel 8, where it will default to Browserslist's defaults query.
建议从 Babel 7 开始,总是显式指定你的 targets,这样在大版本升级时你的输出就不会改变。这个新属性使得在使用 @babel/standalone 自动转换 <script> 标签时可以做到这一点:
🌐 It is recommended to always specify your targets explicitly, already starting in Babel 7, so that your output will not change with the major upgrade. This new attribute makes it possible to do so when using @babel/standalone to automatically transform <script> tags:
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel" data-targets="firefox 97, chrome 102">
const getMessage = () => "Hello World";
document.getElementById("output").innerHTML = getMessage();
</script>
注意,Browserslist 不支持将“当前浏览器”作为目标:你需要自己选择足够旧的目标,以确保用户的浏览器受到支持。
🌐 Note that Browserslist does not support specifying "current browser" as a target: it's your reponsability to pick old enough targets that your users' browsers are supported.
Babel 8.0.0-rc.1
经过 多年的 打磨,Babel 8 终于准备好了。我们将其发布为 8.0.0-rc.1,让更多用户可以尝试并反馈问题,以便最终版本发布前进行改进。除非有用户在试用最新预发布版时的反馈,否则我们不打算再引入其他更改。
🌐 After years in the making, Babel 8 is finally ready. We are releasing it as 8.0.0-rc.1, so that more users can try it out and report problems before the final release. There are no further changes that we plan to introduce, unless due to feedback from users trying the latest pre-releases.
我们引入重大变更的一个指导原则是,升级到 Babel 8 应该很简单:其中大部分在 Babel 7 中已经以可选项的形式引入了,所以你可以在正式升级前开始调整你的代码。
🌐 A guiding principle for the breaking changes we've introduced is that updating to Babel 8 should be easy: most of them have been already introduced in Babel 7 behind an option, so that you can start adapting your code before actually performing the update.
我们准备了一些很棒的资源,帮你了解从 Babel 7 升级到 Babel 8 所需的步骤:
🌐 We've prepared some great resources to navigate through what's needed to upgrade from Babel 7 to Babel 8:
- 一个 Babel 用户迁移指南;
- 一个面向使用 Babel API 的开发者的迁移指南,比如 Babel 插件作者或直接使用我们 AST 的用户;
- Babel 8 文档的网站,目前托管在 https://next.babeljs.io/,直到 Babel 8 稳定为止。
有很多重大变化,希望不会影响我们的用户,但我们对此非常兴奋:一个例子是 Babel 8 将作为 ESM 专用包发布。我们已经尝试了很长时间去弄清楚如何实现这一点,最终随着 Node.js 20 中 require(esm) 的支持,我们对不提供 CommonJS 版本感到放心。
🌐 There are many breaking changes that hopefully will not impact our users, but of which we are incredibly excited about: an example is that Babel 8 will ship as an ESM-only package. We've been trying to figure out how to make this work for very long time, and finally with the require(esm) support shipped in Node.js 20 we are comfortable with not providing a CommonJS alternative.
你也可以在 GitHub 上阅读每个 Babel 8 预发布版本的完整更新日志。
🌐 You can also read the full changelog of each Babel 8 pre-release on GitHub.