interface TransformOptions {
    assumptions?: null | {
        [name: string]: boolean;
    };
    ast?: null | boolean;
    auxiliaryCommentAfter?: null | string;
    auxiliaryCommentBefore?: null | string;
    babelrc?: null | boolean;
    babelrcRoots?: null | boolean | MatchPattern | MatchPattern[];
    browserslistConfigFile?: null | boolean;
    browserslistEnv?: null | string;
    caller?: TransformCaller;
    cloneInputAst?: null | boolean;
    code?: null | boolean;
    comments?: null | boolean;
    compact?: null | boolean | "auto";
    configFile?: null | string | boolean;
    cwd?: null | string;
    env?: null | {
        [index: string]: TransformOptions | null | undefined;
    };
    envName?: string;
    exclude?: MatchPattern | MatchPattern[];
    extends?: null | string;
    filename?: null | string;
    filenameRelative?: null | string;
    generatorOpts?: null | GeneratorOptions;
    getModuleId?: null | ((moduleName) => undefined | null | string);
    highlightCode?: null | boolean;
    ignore?: null | MatchPattern[];
    include?: MatchPattern | MatchPattern[];
    inputSourceMap?: null | InputSourceMap;
    minified?: null | boolean;
    moduleId?: null | string;
    moduleIds?: null | boolean;
    moduleRoot?: null | string;
    only?: null | MatchPattern[];
    overrides?: TransformOptions[];
    parserOpts?: null | ParserOptions;
    plugins?: null | PluginItem[];
    presets?: null | PluginItem[];
    retainLines?: null | boolean;
    root?: null | string;
    rootMode?: "root" | "upward" | "upward-optional";
    shouldPrintComment?: null | ((commentContents) => boolean);
    sourceFileName?: null | string;
    sourceMaps?: null | boolean | "both" | "inline";
    sourceRoot?: null | string;
    sourceType?: null | "module" | "script" | "unambiguous";
    targets?: string | string[] | {
        android?: string;
        browsers?: string | string[];
        chrome?: string;
        deno?: string;
        edge?: string;
        electron?: string;
        esmodules?: boolean;
        firefox?: string;
        ie?: string;
        ios?: string;
        node?: true | "current" | Omit<string, "current">;
        opera?: string;
        rhino?: string;
        safari?: "tp" | Omit<string, "tp">;
        samsung?: string;
    };
    test?: MatchPattern | MatchPattern[];
    wrapPluginVisitorMethod?: null | ((pluginAlias, visitorType, callback) => ((path, state) => void));
}

Properties

assumptions?: null | {
    [name: string]: boolean;
}

Specify which assumptions it can make about your code, to better optimize the compilation result. NOTE: This replaces the various loose options in plugins in favor of top-level options that can apply to multiple plugins

Type declaration

  • [name: string]: boolean
ast?: null | boolean

Include the AST in the returned object

Default: false

auxiliaryCommentAfter?: null | string

Attach a comment after all non-user injected code

Default: null

auxiliaryCommentBefore?: null | string

Attach a comment before all non-user injected code

Default: null

babelrc?: null | boolean

Specify whether or not to use .babelrc and .babelignore files.

Default: true

babelrcRoots?: null | boolean | MatchPattern | MatchPattern[]

Specify which packages should be search for .babelrc files when they are being compiled. true to always search, or a path string or an array of paths to packages to search inside of. Defaults to only searching the "root" package.

Default: (root)

browserslistConfigFile?: null | boolean

Toggles whether or not browserslist config sources are used, which includes searching for any browserslist files or referencing the browserslist key inside package.json. This is useful for projects that use a browserslist config for files that won't be compiled with Babel.

If a string is specified, it must represent the path of a browserslist configuration file. Relative paths are resolved relative to the configuration file which specifies this option, or to cwd when it's passed as part of the programmatic options.

Default: true

browserslistEnv?: null | string

The Browserslist environment to use.

Default: undefined

Utilities may pass a caller object to identify themselves to Babel and pass capability-related flags for use by configs, presets and plugins.

cloneInputAst?: null | boolean

By default babel.transformFromAst will clone the input AST to avoid mutations. Specifying cloneInputAst: false can improve parsing performance if the input AST is not used elsewhere.

Default: true

code?: null | boolean

Enable code generation

Default: true

comments?: null | boolean

Output comments in generated output

Default: true

compact?: null | boolean | "auto"

Do not include superfluous whitespace characters and line terminators. When set to "auto" compact is set to true on input sizes of >500KB

Default: "auto"

configFile?: null | string | boolean

The config file to load Babel's config from. Defaults to searching for "babel.config.js" inside the "root" folder. false will disable searching for config files.

Default: undefined

cwd?: null | string

The working directory that Babel's programmatic options are loaded relative to.

Default: "."

env?: null | {
    [index: string]: TransformOptions | null | undefined;
}

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 envName is production

Default: {}

Type declaration

envName?: string

Defaults to environment variable BABEL_ENV if set, or else NODE_ENV if set, or else it defaults to "development"

Default: env vars

If any of patterns match, the current configuration object is considered inactive and is ignored during config processing.

extends?: null | string

A path to a .babelrc file to extend

Default: null

filename?: null | string

Filename for use in errors etc

Default: "unknown"

filenameRelative?: null | string

Filename relative to sourceRoot

Default: (filename)

generatorOpts?: null | GeneratorOptions

An object containing the options to be passed down to the babel code generator, @babel/generator

Default: {}

getModuleId?: null | ((moduleName) => undefined | null | string)

Specify 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

Default: null

Type declaration

    • (moduleName): undefined | null | string
    • Parameters

      • moduleName: string

      Returns undefined | null | string

highlightCode?: null | boolean

ANSI highlight syntax error code frames

Default: true

ignore?: null | MatchPattern[]

Opposite to the only option. ignore is disregarded if only is specified

Default: null

This option is a synonym for "test"

inputSourceMap?: null | InputSourceMap

A source map object that the output source map will be based on

Default: null

minified?: null | boolean

Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping () from new when safe)

Default: false

moduleId?: null | string

Specify a custom name for module ids

Default: null

moduleIds?: null | boolean

If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for common modules)

Default: false

moduleRoot?: null | string

Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions

Default: (sourceRoot)

only?: null | MatchPattern[]

A 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

Default: null

overrides?: TransformOptions[]

Allows users to provide an array of options that will be merged into the current configuration one at a time. This feature is best used alongside the "test"/"include"/"exclude" options to provide conditions for which an override should apply

parserOpts?: null | ParserOptions

An object containing the options to be passed down to the babel parser, @babel/parser

Default: {}

plugins?: null | PluginItem[]

List of plugins to load and use

Default: []

presets?: null | PluginItem[]

List of presets (a set of plugins) to load and use

Default: []

retainLines?: null | boolean

Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (NOTE: This will not retain the columns)

Default: false

root?: null | string

Specify the "root" folder that defines the location to search for "babel.config.js", and the default folder to allow .babelrc files inside of.

Default: "."

rootMode?: "root" | "upward" | "upward-optional"

This option, combined with the "root" value, defines how Babel chooses its project root. The different modes define different ways that Babel can process the "root" value to get the final project root.

shouldPrintComment?: null | ((commentContents) => boolean)

An optional callback that controls whether a comment should be output or not. Called as shouldPrintComment(commentContents). NOTE: This overrides the comment option when used

Default: null

Type declaration

    • (commentContents): boolean
    • Parameters

      • commentContents: string

      Returns boolean

sourceFileName?: null | string

Set sources[0] on returned source map

Default: (filenameRelative)

sourceMaps?: null | boolean | "both" | "inline"

If 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. This does not emit sourcemap files by itself!

Default: false

sourceRoot?: null | string

The root from which all sources are relative

Default: (moduleRoot)

sourceType?: null | "module" | "script" | "unambiguous"

Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". "unambiguous" will make Babel attempt to guess, based on the presence of ES6 import or export statements. Files with ES6 imports and exports are considered "module" and are otherwise "script".

Default: ("module")

targets?: string | string[] | {
    android?: string;
    browsers?: string | string[];
    chrome?: string;
    deno?: string;
    edge?: string;
    electron?: string;
    esmodules?: boolean;
    firefox?: string;
    ie?: string;
    ios?: string;
    node?: true | "current" | Omit<string, "current">;
    opera?: string;
    rhino?: string;
    safari?: "tp" | Omit<string, "tp">;
    samsung?: string;
}

Describes the environments you support/target for your project. This can either be a browserslist-compatible query (with caveats)

Default: {}

Type declaration

  • Optional android?: string
  • Optional browsers?: string | string[]
  • Optional chrome?: string
  • Optional deno?: string
  • Optional edge?: string
  • Optional electron?: string
  • Optional esmodules?: boolean
  • Optional firefox?: string
  • Optional ie?: string
  • Optional ios?: string
  • Optional node?: true | "current" | Omit<string, "current">
  • Optional opera?: string
  • Optional rhino?: string
  • Optional safari?: "tp" | Omit<string, "tp">
  • Optional samsung?: string

If all patterns fail to match, the current configuration object is considered inactive and is ignored during config processing.

wrapPluginVisitorMethod?: null | ((pluginAlias, visitorType, callback) => ((path, state) => void))

An optional callback that can be used to wrap visitor methods. NOTE: This is useful for things like introspection, and not really needed for implementing anything. Called as wrapPluginVisitorMethod(pluginAlias, visitorType, callback).

Type declaration

    • (pluginAlias, visitorType, callback): ((path, state) => void)
    • Parameters

      • pluginAlias: string
      • visitorType: "exit" | "enter"
      • callback: ((path, state) => void)
          • (path, state): void
          • Parameters

            Returns void

      Returns ((path, state) => void)

        • (path, state): void
        • Parameters

          Returns void