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: import sass file even if not listed in package.json #3627

Merged
merged 6 commits into from
Aug 2, 2021
Merged

fix: import sass file even if not listed in package.json #3627

merged 6 commits into from
Aug 2, 2021

Conversation

roger6106
Copy link
Contributor

Description

Closes #2499.

Vite currently does not work when using @material packages, with no functional workaround. When attempting to load a sass file, the package.json is checked and the main file (which is javascript) is loaded instead of _index.scss. This change adds an additional check specifically for sass files, making sure that the retrieved extension from package.json matches an existing extension. If not, it falls back to the extension method of determining an index file.

Additional context

The tryResolveFile() method has a tryIndex parameter, which uses package.json (if it exists), and then falls back to trying index plus extension / prefix. I add an additional optional skipPackage parameter which is used when a sass extension doesn't match.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Shinigami92 Shinigami92 added the p2-edge-case Bug, but has workaround or limited in scope (priority) label Jun 1, 2021
roger6106 and others added 2 commits June 1, 2021 14:08
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Shinigami92
Shinigami92 previously approved these changes Jun 1, 2021
@patak-dev
Copy link
Member

Thanks for the PR @roger6106. I tested locally and the new tests are passing even when I remove the fix in this PR. They look good to me but seems that Vite was already working correctly in this case. I don't know what difference the issue has that indeed is fixed by your PR. Could you check if new tests could be added that fails without your fix?

@roger6106
Copy link
Contributor Author

Sorry about that. I have corrected the test.

patak-dev
patak-dev previously approved these changes Jun 5, 2021
@roger6106
Copy link
Contributor Author

@Shinigami92: Can you take a look at this again? There's not a functional workaround in my situation, and I'm having to hack SvelteKit so that I keep this change functional with it.

packages/vite/src/node/plugins/resolve.ts Outdated Show resolved Hide resolved
packages/vite/src/node/plugins/resolve.ts Outdated Show resolved Hide resolved
@antfu antfu removed the needs rebase label Aug 2, 2021
@patak-dev patak-dev merged commit a5b2b4f into vitejs:main Aug 2, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot import Sass modules from node_modules: "Error: Can't find stylesheet to import."
4 participants