swcrc
swc configuration files
| 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
Programmatic options.
Properties
1 nested properties
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")
The working directory that all paths in the programmatic options will be resolved relative to.
Defaults to process.cwd().
Configuration ported from babel-preset-env
13 nested properties
Transpiles the broken syntax to the closest non-broken modern syntax
Defaults to false.
The version of the used core js.
Enable all transforms
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"
Note: The type is string because it follows rust's regex syntax.
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.
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.
13 nested properties
23 nested properties
This is experimental, and can be removed without a major version bump.
10 nested properties
Specify the location where SWC stores its intermediate cache files.
Currently only transform plugin uses this. If not specified, SWC will
create .swc directories.
Disable all lint rules.
Disable builtin transforms. If enabled, only Wasm plugins are used.
Use assert instead of with for imports and exports.
This option only works when keepImportAttributes is true.
Emit isolated dts files for each module.
Keep import assertions.
Preserve with in imports and exports.
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.
Run Wasm plugins before stripping TypeScript or decorators.
See https://github.com/swc-project/swc/issues/9132 for more details.
Use @swc/helpers instead of inline helpers.
Keep class names.
12 nested properties
1 nested properties
This can be used to keep the output ascii-only.
If this option is set, minify.format.asciiOnly will be ignored.
Options for transform.
10 nested properties
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
3 nested properties
8 nested properties
Toggles plugins that aid in development, such as
Declares the module specifier to be used for importing the jsx and jsxs factory
functions when using runtime 'automatic'
Replace the function used when compiling JSX expressions.
Defaults to React.createElement.
Replace the component used when compiling JSX fragments.
Defaults to React.Fragment
Enable fast refresh feature for React app
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 onReact.createElementcalls. Requires React to be in scope, which was the standard behavior before React 17."preserve"- Leaves JSX syntax unchanged without transforming it.
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.
Use Object.assign() instead of _extends. Defaults to false.
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.
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
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.
If true, a file is parsed as a script instead of module.
The name to use for the file inside the source map object.
Defaults to path.basename(opts.filenameRelative) when available, or "unknown".
- 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.
The sourceRoot fields to set in the generated source map, if one is desired.
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
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
Note: The type is string because it follows rust's regex syntax.
Definitions
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
If set to true, dynamic imports will be preserved.
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;
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./fooimports, but lazy-initfoodependencies.
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.
Output extension for generated files.
Defaults to js.
If set to true, This will resolve top .mjs
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.
Emits 'use strict' directive.
Defaults to true.
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
If set to true, dynamic imports will be preserved.
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;
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./fooimports, but lazy-initfoodependencies.
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.
Output extension for generated files.
Defaults to js.
If set to true, This will resolve top .mjs
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.
Emits 'use strict' directive.
Defaults to true.
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
Configuration ported from babel-preset-env
Transpiles the broken syntax to the closest non-broken modern syntax
Defaults to false.
The version of the used core js.
Enable all transforms
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
If set to true, dynamic imports will be preserved.
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;
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./fooimports, but lazy-initfoodependencies.
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.
Output extension for generated files.
Defaults to js.
If set to true, This will resolve top .mjs
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.
Emits 'use strict' directive.
Defaults to true.
Defaults to false
Defaults to false
Defaults to false
Defaults to false
Defaults to false
Defaults to false
Defaults to false
Defaults to false
Defaults to false.
Options for inline-global pass.
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 }
These properties are mostly not implemented yet, but it exists to support passing terser config to swc minify without modification.
Currently noop.
Currently noop.
Currently noop.
false: removes all comments'some': preserves some comments'all': preserves all comments{ regex: string }: preserves comments that match the regex
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
Currently noop.
23 nested properties
This is experimental, and can be removed without a major version bump.
10 nested properties
Specify the location where SWC stores its intermediate cache files.
Currently only transform plugin uses this. If not specified, SWC will
create .swc directories.
Disable all lint rules.
Disable builtin transforms. If enabled, only Wasm plugins are used.
Use assert instead of with for imports and exports.
This option only works when keepImportAttributes is true.
Emit isolated dts files for each module.
Keep import assertions.
Preserve with in imports and exports.
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.
Run Wasm plugins before stripping TypeScript or decorators.
See https://github.com/swc-project/swc/issues/9132 for more details.
Use @swc/helpers instead of inline helpers.
Keep class names.
12 nested properties
1 nested properties
This can be used to keep the output ascii-only.
If this option is set, minify.format.asciiOnly will be ignored.
Options for transform.
10 nested properties
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
3 nested properties
8 nested properties
Toggles plugins that aid in development, such as
Declares the module specifier to be used for importing the jsx and jsxs factory
functions when using runtime 'automatic'
Replace the function used when compiling JSX expressions.
Defaults to React.createElement.
Replace the component used when compiling JSX fragments.
Defaults to React.Fragment
Enable fast refresh feature for React app
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 onReact.createElementcalls. Requires React to be in scope, which was the standard behavior before React 17."preserve"- Leaves JSX syntax unchanged without transforming it.
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.
Use Object.assign() instead of _extends. Defaults to false.
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
If set to true, dynamic imports will be preserved.
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;
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./fooimports, but lazy-initfoodependencies.
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.
Output extension for generated files.
Defaults to js.
If set to true, This will resolve top .mjs
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.
Emits 'use strict' directive.
Defaults to true.
Options for inline-global pass.
3 nested properties
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 }
1 nested properties
Toggles plugins that aid in development, such as
Declares the module specifier to be used for importing the jsx and jsxs factory
functions when using runtime 'automatic'
Replace the function used when compiling JSX expressions.
Defaults to React.createElement.
Replace the component used when compiling JSX fragments.
Defaults to React.Fragment
Enable fast refresh feature for React app
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 onReact.createElementcalls. Requires React to be in scope, which was the standard behavior before React 17."preserve"- Leaves JSX syntax unchanged without transforming it.
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.
Use Object.assign() instead of _extends. Defaults to false.
Pass true to not mangle class names.
Pass true to not mangle function names.
Pass true to not mangle private props.
Pass true to mangle names declared in the top level scope.
Options for transform.
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
3 nested properties
Options for inline-global pass.
3 nested properties
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 }
1 nested properties
8 nested properties
Toggles plugins that aid in development, such as
Declares the module specifier to be used for importing the jsx and jsxs factory
functions when using runtime 'automatic'
Replace the function used when compiling JSX expressions.
Defaults to React.createElement.
Replace the component used when compiling JSX fragments.
Defaults to React.Fragment
Enable fast refresh feature for React app
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 onReact.createElementcalls. Requires React to be in scope, which was the standard behavior before React 17."preserve"- Leaves JSX syntax unchanged without transforming it.
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.
Use Object.assign() instead of _extends. Defaults to false.
Defaults to false.
Defaults to false.
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
If set to true, dynamic imports will be preserved.
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;
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./fooimports, but lazy-initfoodependencies.
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.
Output extension for generated files.
Defaults to js.
If set to true, This will resolve top .mjs
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.
Emits 'use strict' directive.
Defaults to true.