import { type BaseModuleConfig } from "https://deno.land/x/live@1.53.6/deps.ts";
Properties
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
.
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-initfoo
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
.
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 ...
;
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 ...
;
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 ...
;
var _foo = require("foo");
var _bar = require("bar");
_foo.default;
_bar.bar;
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