- Babel 是什么?
- 使用指南
- 配置 Babel
- Learn ES2015
- 升级到 Babel 7
- 升级到 Babel 7 (API)
- 编辑器
- 插件
- 预设(Presets)
- 附加说明
- FAQ
- Babel 路线图
- Options
- Config Files
- @babel/cli
- @babel/polyfill
- @babel/plugin-transform-runtime
- @babel/register
- @babel/preset-env
- @babel/preset-stage-0
- @babel/preset-stage-1
- @babel/preset-stage-2
- @babel/preset-stage-3
- @babel/preset-flow
- @babel/preset-react
- babel-preset-minify
- @babel/preset-typescript
- @babel/parser
- @babel/core
- @babel/generator
- @babel/code-frame
- @babel/helpers
- @babel/runtime
- @babel/template
- @babel/traverse
- @babel/types
@babel/core
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
typeEach
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论