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: avoid optimizing non-optimizable external deps #8860

Conversation

bholmesdev
Copy link
Contributor

Description

We discovered that Vite 3 will optimize deps added to ssr.noExternal, even when those deps are not optimizable. This change will check whether a dependency is optimizable before attempting to optimize.

  • if you include a non-optimizable dep in ssr.noExternal 👉 don't optimize, don't log a warning
  • if you include a non-optimizable dep in optimizeDeps.include 👉 don't optimize, DO log a warning

Additional context

  • adds non-optimizable dependency to the optimize-deps playground test
  • adds non-optimizable dependency to the ssr-deps playground test

☝️ Note: no unit tests were added to the .spec.ts files! This is because we're just checking whether your Vite config causes the test suite to bomb. By adding non-optimizable-dep to optimizeDeps.include, for example, we're implicitly checking whether Vite will (wrongly) attempt to optimize.


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.

@netlify
Copy link

netlify bot commented Jun 29, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit c87ad7c
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62bcaf5e9e1ba10009bf1dd8

@bholmesdev bholmesdev changed the title Vite 3 - avoid optimizing non-optimizable external deps fix: avoid optimizing non-optimizable external deps Jun 29, 2022
@patak-dev
Copy link
Member

Thanks a lot @bholmesdev! Great explanation and test case too!
Welcome to Vite Core ⚡

@patak-dev patak-dev merged commit cd8d63b into vitejs:main Jun 29, 2022
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