-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module resolver / path rewrites / aliases #702
Comments
Is there any progress? |
@ws456999 Sadly, not yet. I recently got an idea about such api, but it's blocked by neon-bindings/neon#73 / infinyon/node-bindgen#37 (I'll switch to node-bindgen if required) Edit: I got an idea about the api. I'll see if it works. |
Any progress on this? I also use this feature. |
Im currently using typescript resolveModuleName it would be great to have this. |
Is there any update about this issue ? |
+1 we're migrating to a monorepo layout and it's a bit challenging without this feature |
I started working on this, and I'm not sure if it's correct to support both of babel rewriter and tsconfig rewriter. |
Well I just need to be able to tell the compiler to rewrite certain import paths when it encounters them and follow that new path for the module instead- whatever allows the most customization in this regard is the better one for me. So I'd say the babel one is better? Since it uses a regex syntax and seems like you can use it for quite complex rewrites, as you can see I could do the same thing with a lot fewer lines than I could do with Typescript. |
We only need tsconfig - so from our perspective simple matching is enough. As @lostpebble pointed out babel rewriting seems to be a superset, so sounds like a solution that makes more people happy :D Automated parsing of tsconfig would be nice, but if I need to duplicate this config in |
Thanks for the response! |
NOTE: To get this to work you must specify a
Using |
I think there are some bugs here. // .swcrc
"paths": {
"@src/*": [
"*"
]
} // src/foo/index.ts
import '@src/index' Output: // lib/foo/index.ts
- require('./index')
+ require('../index') When resolving path aliases, it should resolve relative to the base url. Can the base url be read without reading a tsconfig? And what happens is a tsconfig uses |
I'm not sure about this memory, but I thunk you should specify
No |
I specified |
@kdy1 There's nothing in the documentation about |
@athrunsun You can refer to documentation for |
The problem with the current code is that With:
If we have: src/foo/index.js
It should resolve swc/ecmascript/loader/src/resolvers/tsc.rs Lines 121 to 184 in 427df9a
Changing |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the feature
Making use of
babel-plugin-module-resolver
, babel currently allows me to do something like this:Babel plugin or link to the feature description
https://github.com/tleunen/babel-plugin-module-resolver
Additional context
This is exceptionally useful to me because I use a monorepo for my projects, and split up parts of my projects into different modules so that they can be re-used in multiple apps. Things like
@gt/node-utils
and@gt/services
etc.The way I've set it up is that when each of those individual modules are built - their code is imported with something like:
I expect these imports to work, even if the code in those modules hasn't actually been built yet- because I'm always jumping between these separate monorepo modules to improve them and add new features.
I hardly ever actually "build" the modules in my day to day, as I can just use babel to rewrite the paths using
babel-plugin-module-resolver
so when my code is being compiled for dev or even production builds, it always hits the current source code in each module.This could be related to #379, as I am using
tsconfig.json
to set up path aliasing so that TypeScript intellisense functions correctly in my IDE:The text was updated successfully, but these errors were encountered: