babel-plugin-module-resolver
babel-plugin-module-resolver copied to clipboard
does alias support dynamic require via "bundle-loader" or "import()"?
Here is the code, and it seems alias is not working src/scriptes/load_locales.js
function loadLocale(locale,callback){
const localeComponent = require(`bundle-loader?lazy&name=[name]!locales/${locale}`)
localeComponent(callback);
}
loadLocale("en",() => {
console.log("do something");
});
.babelrc
{
"presets": [
["env", {
"modules": false
}]
],
"plugins" : [
[ "module-resolver", {
"cwd": "babelrc",
"alias": {
"^locales/(.+)": "./src/scripts/locale/export/\\2",
},
"stripExtensions": [
".js", ".jsx"
]
}],
"transform-async-generator-functions",
"transform-class-properties",
"transform-export-extensions",
"transform-object-rest-spread",
]
}
expect locales
will transform to ../locale/export/
,but actually not working.
is there a way to support this?
The plugin doesn't currently support the custom loaders from webpack in the paths.
I'd suggest you to put the info in your webpack config and then use a normal path like locales/xxx