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: respect rollupOptions.external for transitive dependencies #8679

Merged
merged 6 commits into from Jun 22, 2022

Conversation

sodatea
Copy link
Member

@sodatea sodatea commented Jun 20, 2022

Description

The regression was brought in by #8280

To be compatible with Vite 2.x behavior:
When rollupOptions.external is set to ['vue'],

  • import ... from 'vue' in dependencies should be preserved;
  • const Vue = require('vue') in dependencies should be transformed to import * as Vue from 'vue' and be preserved;

Ideally, we need a first-class build.external option, but that belongs to another issue/PR. It's fine to postpone it after 3.0 stable is out.


Remaining issues in this PR:

  • rollupOptions.external only accepts string[] | string in the current implementation
    • this is because optimizeDeps.exclude only supports string[]
    • Rollup supports RegExp | RegExp[] and function formats https://rollupjs.org/guide/en/#external
    • If we want to support all these types, we need to extend the ability of optimizeDeps.exclude, either exposing it internally, or open to all end users.
    • Do we really want to do that? Or we can do that in 3.1 or later…
  • The CJS external implementation is naive, there could potentially be more edge cases than in v2. But I think it's acceptable, because this use case shouldn't be encouraged at all.

Additional context


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.

…rently doesn't work for transitive dependencies

It worked in Vite 2.x, though.
@patak-dev patak-dev added this to the 3.0 milestone Jun 21, 2022
@patak-dev patak-dev added the p4-important Violate documented behavior or significantly improves performance (priority) label Jun 21, 2022
@netlify
Copy link

netlify bot commented Jun 22, 2022

Deploy Preview for vite-docs-main ready!

Name Link
🔨 Latest commit fd88ff9
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62b2d13809b32a0009e5a0a3
😎 Deploy Preview https://deploy-preview-8679--vite-docs-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@sodatea sodatea marked this pull request as ready for review June 22, 2022 09:06
@patak-dev
Copy link
Member

Awesome! Looks good to me, merging so we can include it in beta.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants