Options for resolving module entry points in installed modules (import foo from 'bar'
).
Must be set to an object to be enabled. That object may contain the following options.
A list of entry point resolvers.
[
{
"type": "package.json",
"field": "module",
"extensions": [".mjs", ".js"]
},
{
"type": "file",
"path": "./module",
"extensions": [".mjs", ".js"]
}
]
Set to true
to ignore any modules that have an exports
entry (very important).
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"esm-resolver",
{
"module": {
"entry": [
{
"type": "package.json",
"field": "module",
"extensions": [".mjs", ".js"]
}
],
"ignoreExports": true
}
}
]
]
}
src/main.js
import {foo} from 'bar';
output:
import {foo} from 'bar/lib/index.mjs';
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"esm-resolver",
{
"module": {
"entry": [
{
"type": "file",
"path": "./module",
"extensions": [".mjs", ".js"]
}
],
"ignoreExports": true
}
}
]
]
}
src/main.js
import {foo} from 'bar';
output:
import {foo} from 'bar/module.mjs';