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

feat: avoid scanner during build and only optimize CJS in SSR #8932

Merged
merged 4 commits into from Jul 6, 2022

Conversation

patak-dev
Copy link
Member

@patak-dev patak-dev commented Jul 5, 2022

Description

Follow up to:

That enabled back the scanner also during build to fix:

This PR avoids the scanner by refactoring preAlias to register the aliased dependency when needed.

With this, we also now support aliased optimized deps when added in an import by a plugin. This was failing before because they were invisible to the scanner

The PR now also implements the change in heuristics to what needs to be optimized during SSR. Only no-external CJS deps will be optimized during SSR, the user can opt-in using ssr.optimizeDeps.include

Some details:

  • If a dependency is aliased, it isn't optimized by default even if the replacement is CJS. Users can include it to be optimized. We could support this by loading the entry and using mlly, or by recursively finding the package.json to see if the replacement is in a commonjs or module context. I don't know if the complexity is worth it.
  • Added 'vitepress' to optimizeDeps.exclude since it is aliased with replacement join(DIST_CLIENT_PATH, '/index'), and in it a virtual module is used. This was not a problem with commonjs during build, but now dependencies need to be excluded if they are using Vite features.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@netlify
Copy link

netlify bot commented Jul 5, 2022

Deploy Preview for vite-docs-main canceled.

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

@patak-dev patak-dev changed the title feat: refactor preAlias plugin to avoid scanner during build feat: avoid scanner during build and only optimize CJS in SSR Jul 5, 2022
@patak-dev patak-dev merged commit 339d9e3 into main Jul 6, 2022
@patak-dev patak-dev deleted the feat/avoid-scanner-during-build branch July 6, 2022 07:37
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