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: allow define override #8944

merged 3 commits into from
Dec 19, 2022


Copy link

@doman412 doman412 commented Jul 6, 2022


Fix #8921

This allows users to preserve in the build by using define: { '': '' } in the config. Being able to preserve these keywords in the final build is useful for library development builds that want to include HMR code directly in the library.

Additional context

Not sure if this requires more tests than what I've provided, but if so, let me know where and I can add them.

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.

Copy link

netlify bot commented Jul 6, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit ad6659d
🔍 Latest deploy log

Copy link

antfu commented Jul 6, 2022

Vite usually does not transform libraries under node_modules, so having in your lib might not always work. I'd suggest using

Copy link

bluwy commented Jul 6, 2022

Oh I didn't know that. Could it be because in Vite 2, esbuild was incorrectly transforming to ({}).hot? I think this is fixed in Vite 3 now, and it looks like importAnalysis work in node_modules too.

Copy link

antfu commented Jul 6, 2022

If the dep get optimized would that still work?

Copy link

bluwy commented Jul 6, 2022

I guess it would because is preserved in the optimized bundle, and importAnalysis would detect and inject the hot context. I also did a quick test and it seems to work.

Copy link

One thing we changed in Vite 3 is that optimized deps are going now through the vite plugin pipeline, as we need to replicate what the build did in v2 with plugin commonjs

bluwy previously approved these changes Jul 6, 2022
@bluwy bluwy added feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority) labels Jul 9, 2022
@patak-dev patak-dev merged commit 857d578 into vitejs:main Dec 19, 2022
futurGH pushed a commit to futurGH/vite that referenced this pull request Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority)
None yet

Successfully merging this pull request may close these issues.

Preserve for library dev builds
5 participants