-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
🙋 Support project-relative import paths #336
Comments
Hmm I actually really like this idea! 😮 😃 👏 This would be supper useful |
Not sure about the syntax for package root though…
I propose using
As far as I know the “@“ simple doesn’t have any reserved meaning in file paths (@brandon93s maybe it does on Windows?). If not we could also use
|
|
I believe react-native(or one of the tools for it)allows you to define a package.json in any folder. The 'name' property defined in that json file can then be used as an alias for the folder, as if it was in node_modules, just like webpack alias. For example: in app/someDir2/someDir2, i put a package.json file with name = 'myDep', now 'anywhere' in the folder hierarchy i can simply import ... from 'myDep/someFile', the same way webpack alias works. https://medium.com/@davidjwoody/how-to-use-absolute-paths-in-react-native-6b06ae3f65d1 |
Please remember that Another option that I've sometimes stumbled upon is |
Vue-loader uses tilde.
~assets/foo.png
It might be good to stick with existing conventions.
… On Dec 19, 2017, at 5:06 PM, Ron Don Jon ***@***.***> wrote:
Please remember that @ is also a namespace indicator for scopes npm packages, so under no circumstances should a leading @ alone be treated as a reference to the package home; @/ should work though.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Unless anyone has objections, I'm going to add tilde support, like vue-loader. Also I really like the package.json name idea; we might be able to do that. This relies on some FS changes I've been working on; stay tuned. |
@shawwn awesome, many thanks! |
Hello, I wanted to try out parcel with my team's component library and ran into a snag, and i'm wondering if this issue will resolve it. Based off https://github.com/webpack-contrib/sass-loader#imports
Based off the conversation, it seems this fix might resolve my issue, just wanted to check. Thanks! |
IMO this should only resolve to the project root for files actually in the project. For node_modules, it should resolve to the root of that module. e.g. in |
Sure, hence "nearest parent folder" in the initial suggestion. |
So, we have two different approaches to basically the same problem: how to reference files starting at the root of a module. This issue proposes using tilde (e.g. |
@devongovett I think "~" would be the easiest one to implement as it will not be used for an actual absolute path inside the resolver for example when trying to implement it in my pull request i kinda hit a wall for the fs resolves as some already include Also I think we should support absolute paths like I could change my PR to handle what I just said perfectly pretty easily, and it would probably end up being less code than the current implementation |
@devongovett @DeMoorJasper I strongly advise against mixing absolute and project relative paths as it is done in the current implementation of #290. This makes the build machine-dependent! Resolving
IMO, absolute paths should be resolved as exactly that (apart from document-root-relative handling for HTML maybe; I have yet to look into that use case) and paths starting with Other than that, I can't wait for this feature to be released! 😍 |
@shawwn @rondonjon Regarding the question of
That being said, I stand slightly in favor of |
See #850 for an implementation of both absolute and tilde paths, which mean slightly different things. Let me know if you have any feedback! |
Is there any way to set root path once in configuration or CLI? |
For anyone using TypeScript, you're gonna need this to support In
Documentation: https://www.typescriptlang.org/docs/handbook/module-resolution.html in the Path mappings section. |
Projects with a deep folder structure often have import paths with lots of "../../../../../a/b/c/d/actualFile.js" in them because import paths are kind of restricted.
One workaround in webpack is to define custom aliases for the resolver, but this approach would break the zero-configuration approach of parcel.
Would it be possible to have at least an additional notation for "project-relative" imports in parcel, so that the dotdot madness at the beginning could be stopped?
🎛 Configuration (.babelrc, package.json, cli command)
N/A
😯 Current Behavior
Apparently (??) no support for project-relative import paths.
💁 Possible Solution
The text was updated successfully, but these errors were encountered: