Doesn't work with templated strings
I finally got a usecase where I wanted to make a dynamic require() call based on a variable, like so:
require(`App/xxx/${filename}`)
But it doesn't work because we don't know the full filename (since the plugin checks for the file to exist.
Since we made resolving an alias a priority over the root configuration, I believe we could remove the checks for a valid file, and thus allowing templated strings. What do you think @fatfisz ?
I know we had a few tickets around that issue, but couldn't find them with the search terms I used :/
Would love to see a fix for this as well, if possible.
FWIW, I found an old issue referencing the same thing: https://github.com/tleunen/babel-plugin-module-resolver/pull/31
Same issue. Appreciate your plugin nonetheless, will work around. Just wanted to chime in with feedback. 🙂
// works
require('alias/file')
// doesn't work
const filename = 'file';
require('alias/' + filename);
I don't think this issue is connected to template strings, it just doesn't work with expressions. Example:
const file1 = require('path/to/file.js') // Works
const filePath = 'path/to/file.js'
const file2 = require(filePath) // Doesn't work