Skip to content
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

fix: resolve node_modules #15

Merged

Conversation

tanhauhau
Copy link
Contributor

  • fix resolving scoped modules, eg: @scope/package
    • instead of using / to determine the case of deep imports, use path.extname instead (not sure it's the best way) to know it is importing a package or a file
  • fix relative imports within node_modules/.
    • eg: some_package/src/index.js imports './foo.js',
    • because ./foo.js is a relative import, it wasnt rewritten.
    • and if we return some_package/src/index.js when browser requested for '/@modules/some_package', browser will get './foo.js' relative to it, which is '/@modules/foo.js' which is not found.
    • to fix, 302 redirect '/@modules/some_package' to '/@modules/some_package/src/index.js' when resolving, this will help browser to resolve relative files within node_modules

@yyx990803
Copy link
Member

Cool! This is neat, it also gets rid of the need for the source map part, which is essentially dealing with relative imports inside modules.

@yyx990803 yyx990803 merged commit 78ae1b7 into vitejs:master Apr 27, 2020
@tanhauhau tanhauhau deleted the tanhauhau/fix-resolve-node-modules branch April 27, 2020 14:20
antfu pushed a commit that referenced this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants