Skip to content

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

Merged
patak-cat merged 4 commits intomainfrom
feat/avoid-scanner-during-build
Jul 6, 2022
Merged

feat: avoid scanner during build and only optimize CJS in SSR#8932
patak-cat merged 4 commits intomainfrom
feat/avoid-scanner-during-build

Conversation

@patak-cat
Copy link
Copy Markdown
Member

@patak-cat patak-cat 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
Copy Markdown

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

Comment thread packages/vite/src/node/plugins/preAlias.ts
@patak-cat patak-cat 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-cat patak-cat merged commit 339d9e3 into main Jul 6, 2022
@patak-cat patak-cat 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.

2 participants