← 返回命令列表

Linux command

babel 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Transpile

babel [input.js] -o [output.js]

Example

babel [src] -d [dist]

Watch

babel [src] -d [dist] --watch

Example

babel [input.js] -o [output.js] --presets=@babel/preset-env

Inline

babel [input.js] -o [output.js] --source-maps inline

说明

babel is a JavaScript compiler that transforms modern JavaScript (ES6+) into backward-compatible versions for older browsers and environments. It supports JSX, TypeScript, and experimental JavaScript features through plugins and presets. The tool is essential for modern JavaScript development, enabling use of latest language features while maintaining broad compatibility.

参数

-o, --out-file _file_
Output file
-d, --out-dir _dir_
Output directory
-w, --watch
Watch files for changes
-s, --source-maps
Generate source maps
--presets _presets_
Transformation presets
--plugins _plugins_
Transformation plugins
--config-file _path_
Configuration file path
--no-babelrc
Ignore .babelrc files
--minified
Minify output
--compact _mode_
Compact output (true/false/auto)
--ignore _glob_
Glob patterns for files to skip
--extensions _exts_
File extensions to compile (default: .js,.jsx,.es6,.es,.mjs,.cjs)

FAQ

What is the babel command used for?

babel is a JavaScript compiler that transforms modern JavaScript (ES6+) into backward-compatible versions for older browsers and environments. It supports JSX, TypeScript, and experimental JavaScript features through plugins and presets. The tool is essential for modern JavaScript development, enabling use of latest language features while maintaining broad compatibility.

How do I run a basic babel example?

Run `babel [input.js] -o [output.js]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --out-file _file_ do in babel?

Output file