options.md

October 24, 2015 ยท View on GitHub

Usage

babel.transform(code, options);
$ babel --name=value

Options

OptionDefaultDescription
filename"unknown"Filename for use in errors etc.
filenameRelative(filename)Filename relative to sourceRoot.
blacklist[]Array of transformers to exclude. Run babel --help to see a full list of transformers.
whitelist[]Array of transformers to only use. Run babel --help to see a full list of transformers.
loose[]Array of transformers to enable loose mode on.
optional[]Array of transformers to optionally use. Run babel --help to see a full list of transformers. Optional transformers displayed inside square brackets.
nonStandardtrueEnable support for JSX and Flow.
highlightCodetrueANSI highlight syntax error code frames
onlynullA glob, regex, or mixed array of both, matching paths to only compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim.
ignorenullOpposite to the only option.
jsxPragmanullCustom pragma to use for JSX elements
auxiliaryCommentBeforenullAttach a comment before all helper declarations and auxiliary code. eg. "istanbul ignore next"
sourceMapsfalseIf truthy, adds a map property to returned output. If set to "inline", a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to "both" then a map property is returned as well as a source map comment appended.
inputSourceMapnullA source map object that the output source map will be based on.
sourceMapTarget(filenameRelative)Set file on returned source map.
sourceFileName(filenameRelative)Set sources[0] on returned source map.
sourceRoot(moduleRoot)The root from which all sources are relative.
moduleRoot(sourceRoot)Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions.
modules"common"Which module formatter to use. Run babel --help to see a full list of module formatters.
moduleIdsfalseIf truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for common modules)
moduleIdnullSpecify a custom name for module ids.
getModuleIdnullSpecify a custom callback to generate a module id with. Called as getModuleId(moduleName). If falsy value is returned then the generated module id is used.
resolveModuleSourcenullResolve a module source ie. import "SOURCE"; to a custom value. Called as resolveModuleSource(source, filename).
keepModuleIdExtensionsfalseKeep extensions in module ids
externalHelpersfalseUses a reference to babelHelpers instead of placing helpers at the top of your code. Meant to be used in conjunction with external helpers.
codetrueEnable code generation
asttrueInclude the AST in the returned object
stage2Set the experimental proposal stage.
compact"auto"Do not include superfluous whitespace characters and line terminators. When set to "auto" compact is set to true on input sizes of >100KB.
commentstrueOutput comments in generated output.
shouldPrintCommentnullAn optional callback that controls whether a comment should be output or not. Called as shouldPrintComment(commentContents). NOTE: This overrides the comment option when used.
metadataUsedHelpersfalseSee external helpers - selective builds for more information.
env{}

This is an object of keys that represent different environments. For example, you may have:

{ env: { production: { /* specific options */ } } }`

which will use those options when the enviroment variable BABEL_ENV is set to "production". If BABEL_ENV isn't set then NODE_ENV will be used, if it's not set then it defaults to "development"

retainLinesfalse

Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps.

NOTE: This will obviously not retain the columns.
babelrcnullSpecify a custom file path to load a .babelrc config from.