@babel/plugin-proposal-record-and-tuple
安装
🌐 Installation
- npm
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/plugin-proposal-record-and-tuple
yarn add --dev @babel/plugin-proposal-record-and-tuple
pnpm add --save-dev @babel/plugin-proposal-record-and-tuple
bun add --dev @babel/plugin-proposal-record-and-tuple
用法
🌐 Usage
使用配置文件(推荐)
🌐 With a configuration file (Recommended)
{
"plugins": ["@babel/plugin-proposal-record-and-tuple"]
}
通过 CLI
🌐 Via CLI
$ babel --plugins @babel/plugin-proposal-record-and-tuple script.js
通过 Node API
🌐 Via Node API
require("@babel/core").transformSync("code", {
plugins: [["@babel/plugin-proposal-record-and-tuple"]],
});
选项
🌐 Options
importPolyfill
boolean,默认值为 false。
默认情况下,这个插件只会转化提案语法,使用 Record 和 Tuple 全局变量:
🌐 By default this plugin only transforms the proposal syntax, using the Record and Tuple globals:
let a = #[1, 2, 3];
// ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇
let a = Tuple(1, 2, 3);
你要么需要加载一个 polyfill,要么可以传递 "importPolyfill": true 选项将导入注入到 @bloomberg/record-tuple-polyfill,由提案作者维护:
🌐 You either need to load a polyfill, or you can pass the "importPolyfill": true option to inject imports to @bloomberg/record-tuple-polyfill, maintained by the proposal authors:
{
"plugins": [
[
"@babel/plugin-proposal-record-and-tuple",
{
"importPolyfill": true
}
]
]
}
let a = #[1, 2, 3];
// ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇
import { Tuple as _Tuple } from "@bloomberg/record-tuple-polyfill";
let a = _Tuple(1, 2, 3);
别忘了在你的依赖里加上 @bloomberg/record-tuple-polyfill!
🌐 Don't forget to add @bloomberg/record-tuple-polyfill to your dependencies!
polyfillModuleName
string,默认值为 "@bloomberg/record-tuple-polyfill"。
如果你想给不同于 @bloomberg/record-tuple-polyfill 的 polyfill 注入 imports,你可以使用这个选项来指定它的名字。
🌐 If you wish to inject imports to a polyfill different from @bloomberg/record-tuple-polyfill, you can use this option to specify its name.
参考
🌐 References