返回介绍

@babel/core

发布于 2019-12-05 05:03:12 字数 3144 浏览 2529 评论 0 收藏 0

var babel = require("@babel/core");
import { transform } from "@babel/core";
import * as babel from "@babel/core";

All transformations will use your local configuration files.

transform

babel.transform(code: string, transformSync

babel.transformSync(code: string, transformAsync

babel.transformAsync(code: string, transformFile

babel.transformFile(filename: string, transformFileSync

babel.transformFileSync(filename: string, transformFileAsync

babel.transformFileAsync(filename: string, transformFromAst

babel.transformFromAst(ast: Object, code?: string, transformFromAstSync

babel.transformFromAstSync(ast: Object, code?: string, transformFromAstAsync

babel.transformFromAstAsync(ast: Object, code?: string, parse

babel.parse(code: string, parseSync

babel.parseSync(code: string, parseAsync

babel.parseAsync(code: string, Advanced APIs

Many systems that wrap Babel like to automatically inject plugins and presets, or override options. To accomplish this goal, Babel exposes several functions that aid in loading the configuration part-way without transforming.

loadOptions

babel.loadOptions(loadPartialConfig

babel.loadPartialConfig(createConfigItem

babel.createConfigItem(value: string | {} | Function | [string | {} | Function, {} | void], { dirname?: string, type?: "preset" | "plugin" }): ConfigItem

Allows build tooling to create and cache config items up front. If this function is called multiple times for a given plugin, Babel will call the plugin's function itself multiple times. If you have a clear set of expected plugins and presets to inject, pre-constructing the config items would be recommended.

ConfigItem type

Each ConfigItem exposes all of the information Babel knows. The fields are:

  • value: {} | Function - The resolved value of the plugin.
  • options: {} | void - The options object passed to the plugin.
  • dirname: string - The path that the options are relative to.
  • name: string | void - The name that the user gave the plugin instance, e.g. plugins: [ ['env', {}, 'my-env'] ]
  • file: Object | void - Information about the plugin's file, if Babel knows it.
    • request: string - The file that the user requested, e.g. "@babel/env"
    • resolved: string - The full path of the resolved file, e.g. "/tmp/node_modules/@babel/preset-env/lib/index.js"

Options

See the full option list here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文