-
-
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
Add an aliasing system that works for all asset types #25
Comments
You can do this with babel. |
So I take it that your usecase is to avoid typing long relative paths everywhere? In general I'm not a huge fan of doing this as it makes it much harder to reason about where the code you read in a project is coming from. I'd rather stick with the standard Node module resolution algorithm and avoid having each project define its own strategy. If we did something here, I'd want the aliases to be scoped to a particular module. For example, the aliases in the top-level project shouldn't apply within node_modules, and aliases defined within node_modules shouldn't apply to other node_modules. I'm open to proposals for how to implement this, but I can't guarantee that it's something I'll want to support. For JS, the above babel plugin might work OK for now. |
This can't be completely pushed onto Babel since it needs to work across transforms (html, css, etc). I'm also not a fan of doing this for long paths, but it is important for mapping things like "react" to "preact". In which case you do want it to operate across module boundaries. I think we might be able to scope this to packages, but for cases like Preact you'd have one of three options:
it'd have to include their children for those cases like Preact. I can imagine something inside of {
"name": "my-project",
"alias": {
"react": "preact"
}
} |
I started by just attempting to do a "quick switch" from webpack to parcel to see how easy it would be and what results would be produced on a medium to large sized project. The alias issue was the first hurdle. As I started resolving those issues I came across a number of individual gotchas and bumps.
|
As a note, I am very into what I think is unpopular idea, which is to allow setting the effective root of a project. Sort of like a chroot, so you could do: # somewhere.json
{
"root": "./src"
} // file.js
import dogs from '/lists/dogs' and that would get it from This gets around the problem of code that can stop working when a module is installed with the common I think it also gets around the problem of reasoning about where the code you are reading is coming from. It means that a user who has configured this can no longer require a file in their project using an absolute path. I've never seen this done, and it seems a worthwhile trade-off. FootnoteBy this i mean, if you've configured `plugins.module-resolver.root` to `'./src'`, and you haveimport Dog from "components/dog" and then you |
@devongovett the main point it's a way to refer to "srcDir" and "rootDir" like in nuxt, of course it's a bad pattern creating an alias for every folder, but it's awful referencing files using You can just enforce a standard like nuxt or allow alias, but for a "zero config", the idea of just the default: @chee idea as a problem, if a package it's on node_modules and on root what exacly happens? |
Yeah the In fact, parcel already supports a super basic version of that in the form of the Can someone write up a proposal for how this should work in detail? Basically, I think it should work the same way as Whether |
I've tried using babelrc plugins config that works with webpack:
Error in parcel
It would be useful to know where parcel is looking when resolving them module, webpack outputs this for debugging. Looks like it uses Example webpack resolution error:
|
Why not leave it just as |
from @shawwn, cc @sompylasar
|
I'm going to lock this because this issue is to discuss adding aliases to Parcel, not for people to figure out how to get it done today |
See #850 for an implementation of aliases as discussed above. Please comment there if you have any feedback. |
Catch up to v2 Approved-by: Will Binns-Smith Approved-by: Stacy London
Merge v2-2021-02-11 Approved-by: Joey Slater
Is there a way to define alias ? Like webpack config:
The text was updated successfully, but these errors were encountered: