tleunen / babel-plugin-module-resolver

Custom module resolver plugin for Babel
MIT License
3.46k stars 205 forks source link

does alias support dynamic require via "bundle-loader" or "import()"? #279

Open chenliangyu opened 6 years ago

chenliangyu commented 6 years ago

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?

tleunen commented 6 years ago

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