module-alias
module-alias copied to clipboard
[Feature request] Add support for extra extension and also patch path.resolve
These are actually 2 separate features.
- I want to be able to resolve ts files using require.resolve.
- I want to be able to resolve my aliases with path.resolve.
Hey there !
Just to get a bit more context:
- What's your use-case for aliasing Typescript files ? Can you use Typescript's path aliasing instead ? See: https://medium.com/@caludio/how-to-use-module-path-aliases-in-visual-studio-typescript-and-javascript-e7851df8eeaa
- What's the use-case for path.resolve ? I'm thinking this is a bit too far removed from
module-alias, which is about modules, not naked files.
- For the first case when I'm doing
require.resolve('@/aliasedpath/moduleDirWithIndexTsFile'), it won't get resolved. I could use https://nodejs.org/api/modules.html#modules_require_extensions but it's deprecated so I thought it would be nice to have such support here instead so I can make sure it won't conflict with any other lib touching the module system. - The second case is while
require.resolve('alias/file.js')resolves correctly,path.resolve('alias/file.js')is not. For resolving modules it's fine to userequire.resolvebut for anything else (eg. directories) I should usepath.resolve. It would be also a solution for me if a function would be exported by the package to resolve paths, eg:import { resolvePath }from 'module-alias'
module-alias works with compiled JS folder rather than TS sources, so it could resolve only .js from dist (or whatever is destination) folder. If you really need to resolve the .ts source path, you should create a separate alias that would point to src folder rather than dist. So even after it's compiled to JS it would still resolve you .ts file
I'm using TS in runtime with babel-register so I don't have dist folder, only src.