Type object
File match .swcrc
Schema URL https://catalog.lintel.tools/schemas/schemastore/swcrc/latest.json
Source https://swc.rs/schema.json

Validate with Lintel

npx @lintel/lintel check
Type: object

Programmatic options.

Properties

caller Record<string, any>
1 nested properties
name string
configFile string | boolean

Defaults to searching for a default .swcrc file, but can be passed the path of any JS or JSON5 config file.

NOTE: This option does not affect loading of .swcrc files, so while it may be tempting to do configFile: "./foo/.swcrc", it is not recommended. If the given .swcrc is loaded via the standard file-relative logic, you'll end up loading the same config file twice, merging it with itself. If you are linking a specific config file, it is recommended to stick with a naming scheme that is independent of the "swcrc" name.

Defaults to path.resolve(opts.root, ".swcrc")

cwd string

The working directory that all paths in the programmatic options will be resolved relative to.

Defaults to process.cwd().

env object

Configuration ported from babel-preset-env

13 nested properties
bugfixes boolean

Transpiles the broken syntax to the closest non-broken modern syntax

Defaults to false.

coreJs string

The version of the used core js.

debug boolean
dynamicImport boolean
exclude string[]
forceAllTransforms boolean

Enable all transforms

include string[]
loose boolean
mode string
Values: "entry" "usage"
path string
shippedProposals boolean
skip string[]
targets
envName string

The current active environment used during configuration loading. This value is used as the key when resolving "env" configs, and is also available inside configuration functions, plugins, and presets, via the api.env() function.

Defaults to process.env.SWC_ENV || process.env.NODE_ENV || "development"

exclude string[] | string

Note: The type is string because it follows rust's regex syntax.

filename string

The filename associated with the code currently being compiled, if there is one. The filename is optional, but not all of Swc's functionality is available when the filename is unknown, because a subset of options rely on the filename for their functionality.

The three primary cases users could run into are:

  • The filename is exposed to plugins. Some plugins may require the presence of the filename.
  • Options like "test", "exclude", and "ignore" require the filename for string/RegExp matching.
  • .swcrc files are loaded relative to the file being compiled. If this option is omitted, Swc will behave as if swcrc: false has been set.
inlineSourcesContent boolean
inputSourceMap string | boolean

true will attempt to load an input sourcemap from the file itself, if it contains a //# sourceMappingURL=... comment. If no map is found, or the map fails to load and parse, it will be silently discarded.

If an object is provided, it will be treated as the source map object itself.

Defaults to true.

isModule enum
Values: "commonjs" false true "unknown"
jsc object
13 nested properties
assumptions object
23 nested properties
ignoreFunctionName boolean
tsEnumIsReadonly boolean
baseUrl string
experimental object

This is experimental, and can be removed without a major version bump.

10 nested properties
cacheRoot string

Specify the location where SWC stores its intermediate cache files. Currently only transform plugin uses this. If not specified, SWC will create .swc directories.

disableAllLints boolean

Disable all lint rules.

disableBuiltinTransformsForInternalTesting boolean

Disable builtin transforms. If enabled, only Wasm plugins are used.

emitAssertForImportAttributes boolean

Use assert instead of with for imports and exports. This option only works when keepImportAttributes is true.

emitIsolatedDts boolean

Emit isolated dts files for each module.

keepImportAssertions boolean

Keep import assertions.

keepImportAttributes boolean

Preserve with in imports and exports.

optimizeHygiene boolean
plugins array[]

List of custom transform plugins written in WebAssembly. First parameter of tuple indicates the name of the plugin - it can be either a name of the npm package can be resolved, or absolute path to .wasm binary.

Second parameter of tuple is JSON based configuration for the plugin.

runPluginFirst boolean

Run Wasm plugins before stripping TypeScript or decorators.

See https://github.com/swc-project/swc/issues/9132 for more details.

externalHelpers boolean

Use @swc/helpers instead of inline helpers.

keepClassNames boolean

Keep class names.

loose boolean
minify object
12 nested properties
compress TerserCompressOptions | boolean
format
All of: JsFormatOptions object, ToSnakeCaseProperties%3CJsFormatOptions%3E ToSnakeCaseProperties%3CJsFormatOptions%3E
inlineSourcesContent boolean
keep_classnames boolean
keep_fnames boolean
mangle TerserMangleOptions | boolean
module enum
Values: false true "unknown"
outputPath string
safari10 boolean
sourceMap boolean
toplevel boolean
output object
1 nested properties
charset string

This can be used to keep the output ascii-only. If this option is set, minify.format.asciiOnly will be ignored.

Default: "'utf8'"
Values: "ascii" "utf8"
paths Record<string, string[]>
preserveAllComments boolean
target string
Values: "es2015" "es2016" "es2017" "es2018" "es2019" "es2020" "es2021" "es2022" "es2023" "es2024" "es3" "es5" "esnext"
transform object

Options for transform.

10 nested properties
constModules object
  • import { DEBUG } from '@ember/env-flags';
  • import { FEATURE_A, FEATURE_B } from '@ember/features';

See: https://github.com/swc-project/swc/issues/18#issuecomment-466272558

1 nested properties
globals Record<string, object>
decoratorVersion string
Values: "2021-12" "2022-03"
optimizer object
3 nested properties
globals object

Options for inline-global pass.

jsonify object
simplify boolean
react object
8 nested properties
development boolean

Toggles plugins that aid in development, such as

importSource string

Declares the module specifier to be used for importing the jsx and jsxs factory functions when using runtime 'automatic'

Default: "react"
pragma string

Replace the function used when compiling JSX expressions.

Defaults to React.createElement.

pragmaFrag string

Replace the component used when compiling JSX fragments.

Defaults to React.Fragment

refresh object | boolean

Enable fast refresh feature for React app

runtime string

Decides which runtime to use when transforming JSX.

  • "automatic" - Automatically imports the functions that JSX transpiles to. This is the modern approach introduced in React 17+ that eliminates the need to manually import React in every file that uses JSX.
  • "classic" - Uses the traditional JSX transform that relies on React.createElement calls. Requires React to be in scope, which was the standard behavior before React 17.
  • "preserve" - Leaves JSX syntax unchanged without transforming it.
Default: "classic"
Values: "automatic" "classic" "preserve"
throwIfNamespace boolean

Toggles whether or not to throw an error if a XML namespaced tag name is used. For example: <f:image />

Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it.

useBuiltins boolean

Use Object.assign() instead of _extends. Defaults to false.

treatConstEnumAsEnum boolean
tsEnumIsMutable boolean
minify boolean
outputPath string

Destination path. Note that this value is used only to fix source path of source map files and swc does not write output to this path.

plugin object
root string

The initial path that will be processed based on the "rootMode" to determine the conceptual root folder for the current Swc project. This is used in two primary cases:

  • The base directory when checking for the default "configFile" value
  • The default value for "swcrcRoots".

Defaults to opts.cwd

rootMode string

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

"root" - Passes the "root" value through as unchanged. "upward" - Walks upward from the "root" directory, looking for a directory containing a swc.config.js file, and throws an error if a swc.config.js is not found. "upward-optional" - Walk upward from the "root" directory, looking for a directory containing a swc.config.js file, and falls back to "root" if a swc.config.js is not found.

"root" is the default mode because it avoids the risk that Swc will accidentally load a swc.config.js that is entirely outside of the current project folder. If you use "upward-optional", be aware that it will walk up the directory structure all the way to the filesystem root, and it is always possible that someone will have a forgotten swc.config.js in their home directory, which could cause unexpected errors in your builds.

Users with monorepo project structures that run builds/tests on a per-package basis may well want to use "upward" since monorepos often have a swc.config.js in the project root. Running Swc in a monorepo subdirectory without "upward", will cause Swc to skip loading any swc.config.js files in the project root, which can lead to unexpected errors and compilation failure.

Values: "root" "upward" "upward-optional"
script boolean

If true, a file is parsed as a script instead of module.

sourceFileName string

The name to use for the file inside the source map object.

Defaults to path.basename(opts.filenameRelative) when available, or "unknown".

sourceMaps enum
  • true to generate a sourcemap for the code and include it in the result object.
  • "inline" to generate a sourcemap and append it as a data URL to the end of the code, but not include it in the result object.

swc-cli overloads some of these to also affect how maps are written to disk:

  • true will write the map to a .map file on disk
  • "inline" will write the file directly, so it will have a data: containing the map
  • Note: These options are bit weird, so it may make the most sense to just use true and handle the rest in your own code, depending on your use case.
Values: false "inline" true
sourceRoot string

The sourceRoot fields to set in the generated source map, if one is desired.

swcrc boolean

true will enable searching for configuration files relative to the "filename" provided to Swc.

A swcrc value passed in the programmatic options will override one set within a configuration file.

Note: .swcrc files are only loaded if the current "filename" is inside of a package that matches one of the "swcrcRoots" packages.

Defaults to true as long as the filename option has been specified

swcrcRoots MatchPattern | MatchPattern[] | boolean

By default, Babel will only search for .babelrc files within the "root" package because otherwise Babel cannot know if a given .babelrc is meant to be loaded, or if it's "plugins" and "presets" have even been installed, since the file being compiled could be inside node_modules, or have been symlinked into the project.

This option allows users to provide a list of other packages that should be considered "root" packages when considering whether to load .babelrc files.

For example, a monorepo setup that wishes to allow individual packages to have their own configs might want to do

Defaults to opts.root

test string[] | string

Note: The type is string because it follows rust's regex syntax.

Definitions

AmdConfig object
allowTopLevelThis boolean
exportInteropAnnotation boolean

Emits cjs-module-lexer annotation cjs-module-lexer is used in Node.js core for detecting the named exports available when importing a CJS module into ESM. swc will emit cjs-module-lexer detectable annotation with this option enabled.

Defaults to true if import_interop is Node, else false

ignoreDynamic boolean

If set to true, dynamic imports will be preserved.

importInterop string

Defaults to swc.

CommonJS modules and ECMAScript modules are not fully compatible. However, compilers, bundlers and JavaScript runtimes developed different strategies to make them work together as well as possible.

  • swc (alias: babel)

When using exports with swc a non-enumerable __esModule property is exported This property is then used to determine if the import is the default export or if it contains the default export.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

function _interop_require_default(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

var _foo = _interop_require_default(require("foo"));
var _bar = require("bar");

_foo.default;
_bar.bar;

When this import interop is used, if both the imported and the importer module are compiled with swc they behave as if none of them was compiled.

This is the default behavior.

  • node

When importing CommonJS files (either directly written in CommonJS, or generated with a compiler) Node.js always binds the default export to the value of module.exports.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo;
_bar.bar;

This is not exactly the same as what Node.js does since swc allows accessing any property of module.exports as a named export, while Node.js only allows importing statically analyzable properties of module.exports. However, any import working in Node.js will also work when compiled with swc using importInterop: "node".

  • none

If you know that the imported file has been transformed with a compiler that stores the default export on exports.default (such as swc or Babel), you can safely omit the _interop_require_default helper.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo.default;
_bar.bar;
Values: "babel" "node" "none" "swc"
lazy string[] | boolean

Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.

This can improve initial load time of your module because evaluating dependencies up front is sometimes entirely un-necessary. This is especially the case when implementing a library module.

The value of lazy has a few possible effects:

  • false - No lazy initialization of any imported module.
  • true - Do not lazy-initialize local ./foo imports, but lazy-init foo dependencies.

Local paths are much more likely to have circular dependencies, which may break if loaded lazily, so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical.

  • Array<string> - Lazy-initialize all imports with source matching one of the given strings.

The two cases where imports can never be lazy are:

  • import "foo";

Side-effect imports are automatically non-lazy since their very existence means that there is no binding to later kick off initialization.

  • export * from "foo"

Re-exporting all names requires up-front execution because otherwise there is no way to know what names need to be exported.

Defaults to false.

moduleId string
noInterop boolean
outFileExtension string

Output extension for generated files.

Defaults to js.

Values: "cjs" "js" "mjs"
preserveImportMeta boolean
resolveFully boolean

If set to true, This will resolve top .mjs

strict boolean

By default, when using exports with babel a non-enumerable __esModule property is exported. In some cases this property is used to determine if the import is the default export or if it contains the default export.

In order to prevent the __esModule property from being exported, you can set the strict option to true.

Defaults to false.

strictMode boolean

Emits 'use strict' directive.

Defaults to true.

type string
Constant: "amd"
Assumptions object
ignoreFunctionName boolean
tsEnumIsReadonly boolean
CallerOptions Record<string, any>
name string
CommonJsConfig object
allowTopLevelThis boolean
exportInteropAnnotation boolean

Emits cjs-module-lexer annotation cjs-module-lexer is used in Node.js core for detecting the named exports available when importing a CJS module into ESM. swc will emit cjs-module-lexer detectable annotation with this option enabled.

Defaults to true if import_interop is Node, else false

ignoreDynamic boolean

If set to true, dynamic imports will be preserved.

importInterop string

Defaults to swc.

CommonJS modules and ECMAScript modules are not fully compatible. However, compilers, bundlers and JavaScript runtimes developed different strategies to make them work together as well as possible.

  • swc (alias: babel)

When using exports with swc a non-enumerable __esModule property is exported This property is then used to determine if the import is the default export or if it contains the default export.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

function _interop_require_default(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

var _foo = _interop_require_default(require("foo"));
var _bar = require("bar");

_foo.default;
_bar.bar;

When this import interop is used, if both the imported and the importer module are compiled with swc they behave as if none of them was compiled.

This is the default behavior.

  • node

When importing CommonJS files (either directly written in CommonJS, or generated with a compiler) Node.js always binds the default export to the value of module.exports.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo;
_bar.bar;

This is not exactly the same as what Node.js does since swc allows accessing any property of module.exports as a named export, while Node.js only allows importing statically analyzable properties of module.exports. However, any import working in Node.js will also work when compiled with swc using importInterop: "node".

  • none

If you know that the imported file has been transformed with a compiler that stores the default export on exports.default (such as swc or Babel), you can safely omit the _interop_require_default helper.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo.default;
_bar.bar;
Values: "babel" "node" "none" "swc"
lazy string[] | boolean

Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.

This can improve initial load time of your module because evaluating dependencies up front is sometimes entirely un-necessary. This is especially the case when implementing a library module.

The value of lazy has a few possible effects:

  • false - No lazy initialization of any imported module.
  • true - Do not lazy-initialize local ./foo imports, but lazy-init foo dependencies.

Local paths are much more likely to have circular dependencies, which may break if loaded lazily, so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical.

  • Array<string> - Lazy-initialize all imports with source matching one of the given strings.

The two cases where imports can never be lazy are:

  • import "foo";

Side-effect imports are automatically non-lazy since their very existence means that there is no binding to later kick off initialization.

  • export * from "foo"

Re-exporting all names requires up-front execution because otherwise there is no way to know what names need to be exported.

Defaults to false.

noInterop boolean
outFileExtension string

Output extension for generated files.

Defaults to js.

Values: "cjs" "js" "mjs"
preserveImportMeta boolean
resolveFully boolean

If set to true, This will resolve top .mjs

strict boolean

By default, when using exports with babel a non-enumerable __esModule property is exported. In some cases this property is used to determine if the import is the default export or if it contains the default export.

In order to prevent the __esModule property from being exported, you can set the strict option to true.

Defaults to false.

strictMode boolean

Emits 'use strict' directive.

Defaults to true.

type string
Constant: "commonjs"
ConstModulesConfig object
  • import { DEBUG } from '@ember/env-flags';
  • import { FEATURE_A, FEATURE_B } from '@ember/features';

See: https://github.com/swc-project/swc/issues/18#issuecomment-466272558

globals Record<string, object>
EnvConfig object

Configuration ported from babel-preset-env

bugfixes boolean

Transpiles the broken syntax to the closest non-broken modern syntax

Defaults to false.

coreJs string

The version of the used core js.

debug boolean
dynamicImport boolean
exclude string[]
forceAllTransforms boolean

Enable all transforms

include string[]
loose boolean
mode string
Values: "entry" "usage"
path string
shippedProposals boolean
skip string[]
targets
Es6Config object
allowTopLevelThis boolean
exportInteropAnnotation boolean

Emits cjs-module-lexer annotation cjs-module-lexer is used in Node.js core for detecting the named exports available when importing a CJS module into ESM. swc will emit cjs-module-lexer detectable annotation with this option enabled.

Defaults to true if import_interop is Node, else false

ignoreDynamic boolean

If set to true, dynamic imports will be preserved.

importInterop string

Defaults to swc.

CommonJS modules and ECMAScript modules are not fully compatible. However, compilers, bundlers and JavaScript runtimes developed different strategies to make them work together as well as possible.

  • swc (alias: babel)

When using exports with swc a non-enumerable __esModule property is exported This property is then used to determine if the import is the default export or if it contains the default export.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

function _interop_require_default(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

var _foo = _interop_require_default(require("foo"));
var _bar = require("bar");

_foo.default;
_bar.bar;

When this import interop is used, if both the imported and the importer module are compiled with swc they behave as if none of them was compiled.

This is the default behavior.

  • node

When importing CommonJS files (either directly written in CommonJS, or generated with a compiler) Node.js always binds the default export to the value of module.exports.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo;
_bar.bar;

This is not exactly the same as what Node.js does since swc allows accessing any property of module.exports as a named export, while Node.js only allows importing statically analyzable properties of module.exports. However, any import working in Node.js will also work when compiled with swc using importInterop: "node".

  • none

If you know that the imported file has been transformed with a compiler that stores the default export on exports.default (such as swc or Babel), you can safely omit the _interop_require_default helper.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo.default;
_bar.bar;
Values: "babel" "node" "none" "swc"
lazy string[] | boolean

Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.

This can improve initial load time of your module because evaluating dependencies up front is sometimes entirely un-necessary. This is especially the case when implementing a library module.

The value of lazy has a few possible effects:

  • false - No lazy initialization of any imported module.
  • true - Do not lazy-initialize local ./foo imports, but lazy-init foo dependencies.

Local paths are much more likely to have circular dependencies, which may break if loaded lazily, so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical.

  • Array<string> - Lazy-initialize all imports with source matching one of the given strings.

The two cases where imports can never be lazy are:

  • import "foo";

Side-effect imports are automatically non-lazy since their very existence means that there is no binding to later kick off initialization.

  • export * from "foo"

Re-exporting all names requires up-front execution because otherwise there is no way to know what names need to be exported.

Defaults to false.

noInterop boolean
outFileExtension string

Output extension for generated files.

Defaults to js.

Values: "cjs" "js" "mjs"
preserveImportMeta boolean
resolveFully boolean

If set to true, This will resolve top .mjs

strict boolean

By default, when using exports with babel a non-enumerable __esModule property is exported. In some cases this property is used to determine if the import is the default export or if it contains the default export.

In order to prevent the __esModule property from being exported, you can set the strict option to true.

Defaults to false.

strictMode boolean

Emits 'use strict' directive.

Defaults to true.

type string
Constant: "es6"
EsParserConfig object
allowReturnOutsideFunction boolean

Defaults to false

allowSuperOutsideMethod boolean

Defaults to false

autoAccessors boolean

Defaults to false

classPrivateProperty boolean
classProperty boolean
decorators boolean

Defaults to false

decoratorsBeforeExport boolean

Defaults to false

dynamicImport boolean
explicitResourceManagement boolean

Defaults to false

exportDefaultFrom boolean

Defaults to false

exportNamespaceFrom boolean
functionBind boolean

Defaults to false

importAssertions boolean
importAttributes boolean
importMeta boolean
jsx boolean

Defaults to false.

nullishCoalescing boolean
numericSeparator boolean
optionalChaining boolean
privateMethod boolean
syntax string
Constant: "ecmascript"
topLevelAwait boolean
GlobalPassOption object

Options for inline-global pass.

envs string[] | Record%3Cstring,string%3E

Names of environment variables that should be inlined with the value of corresponding env during build.

Defaults to ["NODE_ENV", "SWC_ENV"]

Replaces typeof calls for passed variables with corresponding value

e.g. { window: 'object' }

Global variables that should be inlined with passed value.

e.g. { __DEBUG__: true }

JsFormatOptions object

These properties are mostly not implemented yet, but it exists to support passing terser config to swc minify without modification.

asciiOnly boolean

Currently noop.

Default: false
beautify boolean

Currently noop.

Default: false
braces boolean

Currently noop.

Default: false
comments object | enum
  • false: removes all comments
  • 'some': preserves some comments
  • 'all': preserves all comments
  • { regex: string }: preserves comments that match the regex
Default: false
indentLevel number

Currently noop.

indentStart number

Currently noop.

inlineScript boolean

Currently noop.

keepNumbers number

Currently noop.

keepQuotedProps boolean

Currently noop.

maxLineLen boolean | number

Currently noop.

preamble string

Currently noop.

preserveAnnotations boolean

Currently noop.

quoteKeys boolean

Currently noop.

quoteStyle boolean

Currently noop.

safari10 boolean

Currently noop.

semicolons boolean

Currently noop.

shebang boolean

Currently noop.

webkit boolean

Currently noop.

wrapFuncArgs boolean

Currently noop.

wrapIife boolean

Currently noop.

JsMinifyOptions object
compress TerserCompressOptions | boolean
format
All of: JsFormatOptions object, ToSnakeCaseProperties%3CJsFormatOptions%3E ToSnakeCaseProperties%3CJsFormatOptions%3E
inlineSourcesContent boolean
keep_classnames boolean
keep_fnames boolean
mangle TerserMangleOptions | boolean
module enum
Values: false true "unknown"
outputPath string
safari10 boolean
sourceMap boolean
toplevel boolean
JscConfig object
assumptions object
23 nested properties
ignoreFunctionName boolean
tsEnumIsReadonly boolean
baseUrl string
experimental object

This is experimental, and can be removed without a major version bump.

10 nested properties
cacheRoot string

Specify the location where SWC stores its intermediate cache files. Currently only transform plugin uses this. If not specified, SWC will create .swc directories.

disableAllLints boolean

Disable all lint rules.

disableBuiltinTransformsForInternalTesting boolean

Disable builtin transforms. If enabled, only Wasm plugins are used.

emitAssertForImportAttributes boolean

Use assert instead of with for imports and exports. This option only works when keepImportAttributes is true.

emitIsolatedDts boolean

Emit isolated dts files for each module.

keepImportAssertions boolean

Keep import assertions.

keepImportAttributes boolean

Preserve with in imports and exports.

optimizeHygiene boolean
plugins array[]

List of custom transform plugins written in WebAssembly. First parameter of tuple indicates the name of the plugin - it can be either a name of the npm package can be resolved, or absolute path to .wasm binary.

Second parameter of tuple is JSON based configuration for the plugin.

runPluginFirst boolean

Run Wasm plugins before stripping TypeScript or decorators.

See https://github.com/swc-project/swc/issues/9132 for more details.

externalHelpers boolean

Use @swc/helpers instead of inline helpers.

keepClassNames boolean

Keep class names.

loose boolean
minify object
12 nested properties
compress TerserCompressOptions | boolean
format
All of: JsFormatOptions object, ToSnakeCaseProperties%3CJsFormatOptions%3E ToSnakeCaseProperties%3CJsFormatOptions%3E
inlineSourcesContent boolean
keep_classnames boolean
keep_fnames boolean
mangle TerserMangleOptions | boolean
module enum
Values: false true "unknown"
outputPath string
safari10 boolean
sourceMap boolean
toplevel boolean
output object
1 nested properties
charset string

This can be used to keep the output ascii-only. If this option is set, minify.format.asciiOnly will be ignored.

Default: "'utf8'"
Values: "ascii" "utf8"
paths Record<string, string[]>
preserveAllComments boolean
target string
Values: "es2015" "es2016" "es2017" "es2018" "es2019" "es2020" "es2021" "es2022" "es2023" "es2024" "es3" "es5" "esnext"
transform object

Options for transform.

10 nested properties
constModules object
  • import { DEBUG } from '@ember/env-flags';
  • import { FEATURE_A, FEATURE_B } from '@ember/features';

See: https://github.com/swc-project/swc/issues/18#issuecomment-466272558

1 nested properties
globals Record<string, object>
decoratorVersion string
Values: "2021-12" "2022-03"
optimizer object
3 nested properties
globals object

Options for inline-global pass.

jsonify object
simplify boolean
react object
8 nested properties
development boolean

Toggles plugins that aid in development, such as

importSource string

Declares the module specifier to be used for importing the jsx and jsxs factory functions when using runtime 'automatic'

Default: "react"
pragma string

Replace the function used when compiling JSX expressions.

Defaults to React.createElement.

pragmaFrag string

Replace the component used when compiling JSX fragments.

Defaults to React.Fragment

refresh object | boolean

Enable fast refresh feature for React app

runtime string

Decides which runtime to use when transforming JSX.

  • "automatic" - Automatically imports the functions that JSX transpiles to. This is the modern approach introduced in React 17+ that eliminates the need to manually import React in every file that uses JSX.
  • "classic" - Uses the traditional JSX transform that relies on React.createElement calls. Requires React to be in scope, which was the standard behavior before React 17.
  • "preserve" - Leaves JSX syntax unchanged without transforming it.
Default: "classic"
Values: "automatic" "classic" "preserve"
throwIfNamespace boolean

Toggles whether or not to throw an error if a XML namespaced tag name is used. For example: <f:image />

Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it.

useBuiltins boolean

Use Object.assign() instead of _extends. Defaults to false.

treatConstEnumAsEnum boolean
tsEnumIsMutable boolean
JscTarget string
MatchPattern object
ModuleConfig Es6Config | CommonJsConfig | UmdConfig | AmdConfig | NodeNextConfig | SystemjsConfig
NodeNextConfig object
allowTopLevelThis boolean
exportInteropAnnotation boolean

Emits cjs-module-lexer annotation cjs-module-lexer is used in Node.js core for detecting the named exports available when importing a CJS module into ESM. swc will emit cjs-module-lexer detectable annotation with this option enabled.

Defaults to true if import_interop is Node, else false

ignoreDynamic boolean

If set to true, dynamic imports will be preserved.

importInterop string

Defaults to swc.

CommonJS modules and ECMAScript modules are not fully compatible. However, compilers, bundlers and JavaScript runtimes developed different strategies to make them work together as well as possible.

  • swc (alias: babel)

When using exports with swc a non-enumerable __esModule property is exported This property is then used to determine if the import is the default export or if it contains the default export.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

function _interop_require_default(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

var _foo = _interop_require_default(require("foo"));
var _bar = require("bar");

_foo.default;
_bar.bar;

When this import interop is used, if both the imported and the importer module are compiled with swc they behave as if none of them was compiled.

This is the default behavior.

  • node

When importing CommonJS files (either directly written in CommonJS, or generated with a compiler) Node.js always binds the default export to the value of module.exports.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo;
_bar.bar;

This is not exactly the same as what Node.js does since swc allows accessing any property of module.exports as a named export, while Node.js only allows importing statically analyzable properties of module.exports. However, any import working in Node.js will also work when compiled with swc using importInterop: "node".

  • none

If you know that the imported file has been transformed with a compiler that stores the default export on exports.default (such as swc or Babel), you can safely omit the _interop_require_default helper.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo.default;
_bar.bar;
Values: "babel" "node" "none" "swc"
lazy string[] | boolean

Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.

This can improve initial load time of your module because evaluating dependencies up front is sometimes entirely un-necessary. This is especially the case when implementing a library module.

The value of lazy has a few possible effects:

  • false - No lazy initialization of any imported module.
  • true - Do not lazy-initialize local ./foo imports, but lazy-init foo dependencies.

Local paths are much more likely to have circular dependencies, which may break if loaded lazily, so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical.

  • Array<string> - Lazy-initialize all imports with source matching one of the given strings.

The two cases where imports can never be lazy are:

  • import "foo";

Side-effect imports are automatically non-lazy since their very existence means that there is no binding to later kick off initialization.

  • export * from "foo"

Re-exporting all names requires up-front execution because otherwise there is no way to know what names need to be exported.

Defaults to false.

noInterop boolean
outFileExtension string

Output extension for generated files.

Defaults to js.

Values: "cjs" "js" "mjs"
preserveImportMeta boolean
resolveFully boolean

If set to true, This will resolve top .mjs

strict boolean

By default, when using exports with babel a non-enumerable __esModule property is exported. In some cases this property is used to determine if the import is the default export or if it contains the default export.

In order to prevent the __esModule property from being exported, you can set the strict option to true.

Defaults to false.

strictMode boolean

Emits 'use strict' directive.

Defaults to true.

type string
Constant: "nodenext"
OptimizerConfig object
globals object

Options for inline-global pass.

3 nested properties
envs string[] | Record%3Cstring,string%3E

Names of environment variables that should be inlined with the value of corresponding env during build.

Defaults to ["NODE_ENV", "SWC_ENV"]

Replaces typeof calls for passed variables with corresponding value

e.g. { window: 'object' }

Global variables that should be inlined with passed value.

e.g. { __DEBUG__: true }

jsonify object
1 nested properties
minCost number
simplify boolean
ParserConfig TsParserConfig | EsParserConfig
Plugin object
ReactConfig object
development boolean

Toggles plugins that aid in development, such as

importSource string

Declares the module specifier to be used for importing the jsx and jsxs factory functions when using runtime 'automatic'

Default: "react"
pragma string

Replace the function used when compiling JSX expressions.

Defaults to React.createElement.

pragmaFrag string

Replace the component used when compiling JSX fragments.

Defaults to React.Fragment

refresh object | boolean

Enable fast refresh feature for React app

runtime string

Decides which runtime to use when transforming JSX.

  • "automatic" - Automatically imports the functions that JSX transpiles to. This is the modern approach introduced in React 17+ that eliminates the need to manually import React in every file that uses JSX.
  • "classic" - Uses the traditional JSX transform that relies on React.createElement calls. Requires React to be in scope, which was the standard behavior before React 17.
  • "preserve" - Leaves JSX syntax unchanged without transforming it.
Default: "classic"
Values: "automatic" "classic" "preserve"
throwIfNamespace boolean

Toggles whether or not to throw an error if a XML namespaced tag name is used. For example: <f:image />

Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it.

useBuiltins boolean

Use Object.assign() instead of _extends. Defaults to false.

Record<string,any> object
Record<string,string> object
SystemjsConfig object
allowTopLevelThis boolean
type string
Constant: "systemjs"
TerserCompressOptions object
arguments boolean
arrows boolean
booleans boolean
booleans_as_integers boolean
collapse_vars boolean
comparisons boolean
computed_props boolean
conditionals boolean
const_to_let boolean
dead_code boolean
defaults boolean
directives boolean
drop_console boolean
drop_debugger boolean
evaluate boolean
expression boolean
global_defs
hoist_funs boolean
hoist_props boolean
hoist_vars boolean
ie8 boolean
if_return boolean
inline number
Values: 0 1 2 3
join_vars boolean
keep_classnames boolean
keep_fargs boolean
keep_fnames boolean
keep_infinity boolean
loops boolean
module boolean
negate_iife boolean
passes number
properties boolean
pure_funcs string[]
pure_getters
reduce_funcs boolean
reduce_vars boolean
sequences
side_effects boolean
switches boolean
top_retain
toplevel
typeofs boolean
unsafe boolean
unsafe_arrows boolean
unsafe_comps boolean
unsafe_function boolean
unsafe_math boolean
unsafe_methods boolean
unsafe_passes boolean
unsafe_proto boolean
unsafe_regexp boolean
unsafe_symbols boolean
unsafe_undefined boolean
unused boolean
TerserEcmaVersion string | number
TerserMangleOptions object
ie8 boolean
keepClassNames boolean

Pass true to not mangle class names.

keepFnNames boolean

Pass true to not mangle function names.

keepPrivateProps boolean

Pass true to not mangle private props.

keep_classnames boolean
keep_fnames boolean
keep_private_props boolean
props object
reserved string[]
safari10 boolean
topLevel boolean

Pass true to mangle names declared in the top level scope.

toplevel boolean
TerserManglePropertiesOptions object
ToSnakeCaseProperties<JsFormatOptions> object
ascii_only boolean
beautify boolean
braces boolean
comments object | enum
indent_level number
indent_start number
inline_script boolean
keep_numbers number
keep_quoted_props boolean
max_line_len boolean | number
preamble string
preserve_annotations boolean
quote_keys boolean
quote_style boolean
safari10 boolean
semicolons boolean
shebang boolean
webkit boolean
wrap_func_args boolean
wrap_iife boolean
TransformConfig object

Options for transform.

constModules object
  • import { DEBUG } from '@ember/env-flags';
  • import { FEATURE_A, FEATURE_B } from '@ember/features';

See: https://github.com/swc-project/swc/issues/18#issuecomment-466272558

1 nested properties
globals Record<string, object>
decoratorVersion string
Values: "2021-12" "2022-03"
optimizer object
3 nested properties
globals object

Options for inline-global pass.

3 nested properties
envs string[] | Record%3Cstring,string%3E

Names of environment variables that should be inlined with the value of corresponding env during build.

Defaults to ["NODE_ENV", "SWC_ENV"]

Replaces typeof calls for passed variables with corresponding value

e.g. { window: 'object' }

Global variables that should be inlined with passed value.

e.g. { __DEBUG__: true }

jsonify object
1 nested properties
minCost number
simplify boolean
react object
8 nested properties
development boolean

Toggles plugins that aid in development, such as

importSource string

Declares the module specifier to be used for importing the jsx and jsxs factory functions when using runtime 'automatic'

Default: "react"
pragma string

Replace the function used when compiling JSX expressions.

Defaults to React.createElement.

pragmaFrag string

Replace the component used when compiling JSX fragments.

Defaults to React.Fragment

refresh object | boolean

Enable fast refresh feature for React app

runtime string

Decides which runtime to use when transforming JSX.

  • "automatic" - Automatically imports the functions that JSX transpiles to. This is the modern approach introduced in React 17+ that eliminates the need to manually import React in every file that uses JSX.
  • "classic" - Uses the traditional JSX transform that relies on React.createElement calls. Requires React to be in scope, which was the standard behavior before React 17.
  • "preserve" - Leaves JSX syntax unchanged without transforming it.
Default: "classic"
Values: "automatic" "classic" "preserve"
throwIfNamespace boolean

Toggles whether or not to throw an error if a XML namespaced tag name is used. For example: <f:image />

Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it.

useBuiltins boolean

Use Object.assign() instead of _extends. Defaults to false.

treatConstEnumAsEnum boolean
tsEnumIsMutable boolean
TsParserConfig object
decorators boolean

Defaults to false.

dynamicImport boolean
syntax string
Constant: "typescript"
tsx boolean

Defaults to false.

UmdConfig object
allowTopLevelThis boolean
exportInteropAnnotation boolean

Emits cjs-module-lexer annotation cjs-module-lexer is used in Node.js core for detecting the named exports available when importing a CJS module into ESM. swc will emit cjs-module-lexer detectable annotation with this option enabled.

Defaults to true if import_interop is Node, else false

globals Record<string, string>
ignoreDynamic boolean

If set to true, dynamic imports will be preserved.

importInterop string

Defaults to swc.

CommonJS modules and ECMAScript modules are not fully compatible. However, compilers, bundlers and JavaScript runtimes developed different strategies to make them work together as well as possible.

  • swc (alias: babel)

When using exports with swc a non-enumerable __esModule property is exported This property is then used to determine if the import is the default export or if it contains the default export.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

function _interop_require_default(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

var _foo = _interop_require_default(require("foo"));
var _bar = require("bar");

_foo.default;
_bar.bar;

When this import interop is used, if both the imported and the importer module are compiled with swc they behave as if none of them was compiled.

This is the default behavior.

  • node

When importing CommonJS files (either directly written in CommonJS, or generated with a compiler) Node.js always binds the default export to the value of module.exports.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo;
_bar.bar;

This is not exactly the same as what Node.js does since swc allows accessing any property of module.exports as a named export, while Node.js only allows importing statically analyzable properties of module.exports. However, any import working in Node.js will also work when compiled with swc using importInterop: "node".

  • none

If you know that the imported file has been transformed with a compiler that stores the default export on exports.default (such as swc or Babel), you can safely omit the _interop_require_default helper.

import foo from "foo";
import { bar } from "bar";
foo;
bar;

// Is compiled to ...

"use strict";

var _foo = require("foo");
var _bar = require("bar");

_foo.default;
_bar.bar;
Values: "babel" "node" "none" "swc"
lazy string[] | boolean

Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.

This can improve initial load time of your module because evaluating dependencies up front is sometimes entirely un-necessary. This is especially the case when implementing a library module.

The value of lazy has a few possible effects:

  • false - No lazy initialization of any imported module.
  • true - Do not lazy-initialize local ./foo imports, but lazy-init foo dependencies.

Local paths are much more likely to have circular dependencies, which may break if loaded lazily, so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical.

  • Array<string> - Lazy-initialize all imports with source matching one of the given strings.

The two cases where imports can never be lazy are:

  • import "foo";

Side-effect imports are automatically non-lazy since their very existence means that there is no binding to later kick off initialization.

  • export * from "foo"

Re-exporting all names requires up-front execution because otherwise there is no way to know what names need to be exported.

Defaults to false.

noInterop boolean
outFileExtension string

Output extension for generated files.

Defaults to js.

Values: "cjs" "js" "mjs"
preserveImportMeta boolean
resolveFully boolean

If set to true, This will resolve top .mjs

strict boolean

By default, when using exports with babel a non-enumerable __esModule property is exported. In some cases this property is used to determine if the import is the default export or if it contains the default export.

In order to prevent the __esModule property from being exported, you can set the strict option to true.

Defaults to false.

strictMode boolean

Emits 'use strict' directive.

Defaults to true.

type string
Constant: "umd"