babel-plugin-webpack-alias icon indicating copy to clipboard operation
babel-plugin-webpack-alias copied to clipboard

The support for trailing $

Open vmajsuk opened this issue 6 years ago • 0 comments

Hi!

In the webpack docs for resolve.alias there is an option to resolve a specific file by doing this:

resolve: {
    alias: { xyz$: 'path/to/xyz.js' }
}

, and then using it in the code like

import xyz from 'xyz'

However, that does not work with the plugin. What does work is to have a webpack config like this:

resolve: {
    alias: { xyz: 'path/to/xyz.js' }
}

, and using it like this:

import xyz from 'xyz'

This is caused by the following line in the src/index.js:176, I think:

let requiredFilePath = filePath.replace(aliasFrom, relativeFilePath);

I can submit a pr, but I'm just not sure what kind of behavior is expected. Maybe the correct way is checking if aliasFrom ends with $, and, in case it does and the path starts with aliasFrom.slice(1), do filePath.replace(aliasFrom.slice(1), relativeFilePath), so the module remains backward compatible? Or just add the description of the workaround to the README.md?

vmajsuk avatar Oct 22 '17 12:10 vmajsuk