-
-
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
[WIP] resolve '~/' to root path of project #466
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
This should however not resolve to cwd, because this would break if u start a project from a different folder than where the startpoint is located and any usage of '~' inside node_modules.
(U could have a look at my PR for a slightly more accurate but not perfect root solution #290 )
@DeMoorJasper |
@@ -9,6 +9,19 @@ class Resolver { | |||
constructor(options = {}) { | |||
this.options = options; | |||
this.cache = new Map(); | |||
this.pathIndicators = { | |||
// resolve '~/' to root path of project | |||
'~/': path.dirname(this.options.cacheDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would break if source is in another directory than where u executed the parcel command.
This kinda is the same as your previous cwd() implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most projects only need to run under their current directory as the root directory on it, because of the need for convenient reference to resource files
resolvePath(filename) { | ||
for (let [indicator, exactPath] of Object.entries(this.pathIndicators)) { | ||
if (filename.startsWith(indicator)) { | ||
return path.resolve(exactPath, filename.slice(indicator.length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this also handle urlImports in for example html?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it cann't handle in html which is entry
I think, this is not needed. Isnt better just use https://github.com/tleunen/babel-plugin-module-resolver ? |
resolve '~' to root path of project
i support use ~
#336