TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/meteor/meteor/llms.txt
Use this file to discover all available pages before exploring further.
babel-compiler package provides parsing and transpilation capabilities for modern JavaScript syntax in Meteor applications. It supports both Babel and SWC compilers with automatic fallback mechanisms.
Overview
This package exposes the Babel API and SWC compiler for transpiling ECMAScript 2015+ code to run in older browsers and Node.js environments. It automatically chooses between SWC (faster) and Babel (more compatible) based on your configuration.Dependencies
Compilers
BabelCompiler
The main compiler class that can be instantiated with custom features.extraFeatures(Object): Configuration options for compilation featuresmodifyConfig(Function): Optional function to modify the Babel configuration
SwcCompiler
An optimized compiler that always uses SWC for faster transpilation.BabelCompiler with swc: true automatically enabled.
Configuration
Babel Configuration
Configure Babel using.babelrc or package.json:
.babelrc example:
SWC Configuration
Configure SWC using.swcrc or swc.config.js:
.swcrc example:
Meteor Configuration
Control transpiler behavior viapackage.json:
excludeApp- Exclude application code from SWC (boolean or array of patterns)excludeNodeModules- Exclude node_modules from SWC (boolean or array of patterns)excludePackages- Exclude Meteor packages from SWC (boolean or array of patterns)excludeLegacy- Exclude legacy builds from SWCverbose- Enable verbose transpilation logging
API
Babel.compile(source, options, cacheOptions)
Compile JavaScript source code.Babel.getDefaultOptions(extraFeatures)
Get default Babel options with optional feature overrides.Babel.parse(source)
Parse JavaScript source into an AST.Babel.compileForShell(command, cacheOptions)
Compile code for shell execution.Features
Automatic Compiler Selection
The package automatically selects SWC for faster compilation and falls back to Babel when needed:External Helpers
Install@swc/helpers for smaller bundle sizes:
- Smaller bundle size through reduced code duplication
- Faster page loads with less code to parse
- Optional browser caching for vendor chunks
Architecture Support
Different compilation strategies per architecture:- Modern browsers (
web.browser): ES2015+ with minimal transpilation - Legacy browsers (
web.browser.legacy): Full transpilation with polyfills - Node.js (
os.*): Version-specific transpilation - Cordova (
web.cordova): Configurable modern/legacy support
Top-Level Await
Supported in:- Server-side code by default
- Client-side when
METEOR_ENABLE_CLIENT_TOP_LEVEL_AWAIT=true
TypeScript Support
Automatic TypeScript configuration viatsconfig.json:
Caching
SWC Cache
The compiler maintains both in-memory and disk caches:Cache Directory
Set a custom cache directory:Excluded Files
Files excluded from transpilation:*.es5.js- Already ES5 compatible*.min.js- Already minified- Files with
transpile: falseoption - Bare files without CommonJS access
Verbose Logging
Enable detailed transpilation logs:- Compiler used (SWC/Babel/Rspack)
- File path and origin (app/package/node_modules)
- Cache hit/miss status
- Target architecture
- Error messages and tips
Example Usage
Custom Plugin
SWC-Only Compilation
Notes
- Forbidden presets (
babel-preset-meteor,@babel/preset-env,@babel/preset-react) are automatically ignored to prevent conflicts .babelrcfiles must be in the application root directory- The package runs only on the server side
- Rspack output files bypass transpilation as they’re already processed