Options for resolving other source modules in the source files (import foo from './bar'
).
Must be set to an object to be enabled. That object may contain the following options.
A list of extensions to resolve, and optionally the extension that should be used once transpiled.
Takes the form of one of the following.
- Resolve
.js
or.json
in that order.
[".js", ".json"]
- Resolve
.ts
or.json
in that order, uses.js
for imports of.ts
modules in transpiled code.
[[".ts", ".js"], ".json"]
- Resolve
.ts
,.tsx
, or.json
in that order, uses.js
for imports of.ts
and.tsx
modules in transpiled code.
[[[".ts", ".tsx"], ".js"], ".json"]
Set to true
to ignore any source modules that cannot be resolved.
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"esm-resolver",
{
"source": {
"extensions": [".js"]
}
}
]
]
}
src/main.js
import {foo} from './bar';
src/bar.js
export const foo = 123;
output:
import {foo} from './bar.js';
(In practice the TypeScript preset would probably also be used)
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"esm-resolver",
{
"source": {
"extensions": [[".ts", ".js"]]
}
}
]
]
}
src/main.ts
import {foo} from './bar';
Or with extensions included:
import {foo} from './bar.ts';
src/bar.ts
export const foo = 123;
output:
import {foo} from './bar.js';
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"esm-resolver",
{
"source": {
"extensions": [[[".ts", ".js"], ".js"]]
}
}
]
]
}
src/main.ts
import {foo} from './bar';
import {bar} from './foo';
Or with extensions included:
import {foo} from './bar.ts';
import {bar} from './foo.js';
src/bar.ts
export const foo = 123;
src/foo.js
export const bar = 123;
output:
import {foo} from './bar.js';
import {bar} from './foo.js';