risen228 / craco-alias

A craco plugin for automatic aliases generation for Webpack and Jest
MIT License
109 stars 11 forks source link

Does not support aliasing named imports #3

Closed zwigglers closed 4 years ago

zwigglers commented 4 years ago

The current aliases only support aliasing paths. What if I want to alias named imports.

as a trivial example, say instead of importing import * from 'some-installed-library/sub-module' i want to alias it to import * from 'shortened'

with alias

options: {
  source: "options",
  aliases: {
    "shortened": "some-installed-library/sub-module",
  }
}
risen228 commented 4 years ago

@zwigglers It is possible to do this, but in the way that you proposed, we will have to do checks on whether the path is the name of the module, or it's just the path. This will become an unnecessary complication of the plugin logic.

Have you also tried to specifying the module path like that?

options: {
  source: "options",
  aliases: {
    "shortened": "node_modules/some-installed-library/sub-module",
  }
}

Anyway, i'm not sure CRA allows to do that. So I need some time to test it and to think about variants of solving this problem.

zwigglers commented 4 years ago

I tried referencing node_modules as a path but I ran into problems, I think it was because I was using yarn workspaces which puts node_modules outside the root directory which causes other problems with the CRA webpack config.

There is a slight difference in behavior

I think at the very least the documentation should be updated to reflect that this library only supports path aliasing, even though the underlying webpack config allows for named import aliasing.

risen228 commented 4 years ago

I think it should work in V2. But I ran into the problems with types declarations. For some reason, TS thinks that package does not have types, even when @type/package is installed. Trying to find out the reason.