如何使用babel 7添加flatMap? [英] How to add flatMap using babel 7?

查看:159
本文介绍了如何使用babel 7添加flatMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读文章删除Babel的舞台预设通过 babel ,我仍然不完全了解如何添加提案,例如 stage-3 flatMap )到 .babelrc

After reading the article Removing Babel's Stage Presets by babel, I still not fully understand how to add a proposal from, for example, stage-3 (flatMap) to .babelrc.

据我了解,因为 flatMap 可以用ES5编写,那么我需要一个polyfill而不是插件。我在--save-dev下安装了 @ babel / polyfill ,但浏览器仍然告诉我这个方法不存在。我想 @ babel / polyfill 不包括实验性功能。

As far as I understand, because flatMap can be written in ES5, then I need a polyfill and not a plugin. I installed @babel/polyfill under --save-dev but the browser still tells me that this method doesn't exist. I guess that @babel/polyfill doesn't cover experimental features.

推荐答案

flatMap已从@ babel / polyfill中移除给babel 7.您需要直接从core-js中包含它,例如

flatMap was removed from @babel/polyfill for babel 7. You need to include it directly from core-js, like

import "core-js/fn/array/flat-map";

或者如果你想要babel 6曾经使用的所有polyfills包括:

Or if you want all of the polyfills that babel 6 used to include:

import "core-js/shim";

参见: https://github.com/babel/babel/pull/8440 (或更直接地, v7升级指南的相关部分

See: https://github.com/babel/babel/pull/8440 (or more directly, the relevant section of the v7 upgrade guide)

(另外,不要担心必须添加一个新包:你的依赖树中已经有了core-js;这就是babel / polyfill得到的地方其余的Stage 4+ polyfills

(Also, don't worry about having to add a new package: you already have core-js in your dependency tree; that's where babel/polyfill gets the rest of its Stage 4+ polyfills)

这篇关于如何使用babel 7添加flatMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆