babel Command: Transpile JS in CI
babel transpiles modern JS/TS/JSX down to a target-compatible JavaScript.
The Babel CLI (@babel/cli) compiles modern JavaScript, JSX, and TypeScript into widely supported output. In CI it runs as a library build step, emitting transpiled files and source maps for publishing or further bundling.
Common flags
--out-dir DIR/-d DIR- compile a directory into DIR--out-file FILE/-o FILE- compile to a single output file--config-file PATH- use a specific Babel config--extensions .ts,.tsx- file extensions to compile--source-maps/-s- emit source maps (useinlinefor inline maps)--copy-files- copy non-compilable files to the output dir--ignore "**/*.test.js"- skip matching files
Example in CI
Transpile a TypeScript src tree to a lib directory with source maps:
shell
babel src --out-dir lib --extensions .ts,.tsx --source-maps --copy-filesCommon errors in CI
- Cannot find module '@babel/preset-env' - preset not installed
- SyntaxError: Unexpected token - missing a preset/plugin for that syntax
- .babelrc / babel.config.js: Error while loading config - bad config file
- Error: Cannot resolve plugin X - plugin name typo or not installed
Key takeaways
--out-dirbuilds a tree;--out-fileconcatenates to one file.- List
--extensionsexplicitly when compiling TypeScript/JSX. - Most CI failures are missing presets/plugins not in package.json.
Related guides
swc Command: Fast JS/TS Compile in CIswc is a Rust-based JS/TS compiler. Reference for --out-dir, --config-file, --source-maps, -C options, and th…
tsc Command: Compile TypeScript in CItsc is the TypeScript compiler. Reference for --noEmit, --project, --watch, --build, --outDir, --strict, and…
esbuild Command: Bundle & Compile in CIesbuild is a fast Go-based bundler/compiler. Reference for --bundle, --outfile, --minify, --platform, --targe…