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(vite-plugin): production builds (fix: #17267) #17272

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

yurks
Copy link

@yurks yurks commented Jun 10, 2024

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Documentation
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the dev branch (or v[X] branch)
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix: #xxx[,#xxx], where "xxx" is the issue number)
  • It's been tested on a Cordova (iOS, Android) app
  • It's been tested on an Electron app
  • Any necessary documentation has been added or updated in the docs or explained in the PR's description.

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to start a new feature discussion first and wait for approval before working on it)

Other information:

@yurks
Copy link
Author

yurks commented Jun 10, 2024

#17267

@rstoenescu
Copy link
Member

Hi @yurks ,

Thank you for contributing!

The problem with this is that the "vite preview" command is run by default with "serve" command and "production" mode. As per the Vite docs on the "vite preview" cmd: "Locally preview the production build". If we only look at the command as in this PR, then "vite preview" will produce a hybrid compilation, wrongly assuming it's a "dev" build.

What are your thoughts on this?

@rstoenescu
Copy link
Member

Vite command viteConf.command viteConf.mode
serve serve development
build build production
preview serve production

@yurks
Copy link
Author

yurks commented Aug 16, 2024

@rstoenescu but preview could be run with another mode, like vite preview --mode staging, and current implementation will fail as well.

And yes, I forgot about preview ;) It looks like more correct condition for enabling tree-shaking would be command === 'serve' && mode === 'development'. What do you think?

@athisun
Copy link
Contributor

athisun commented Mar 3, 2025

@yurks I think the best solution may be to directly check process.env.NODE_ENV instead of using envConfig.mode. I explain the thinking in this issue (which I may need to close as a duplicate): #17859. Do you agree? And could we update this PR, or should I open a new one?

To maintain the fix for Vitest in Issue #15997 (PR #15999), instead of process.env.NODE_ENV === 'development', we should use either:

  • process.env.NODE_ENV !== 'production' (I think this is ideal), or
  • process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'

Using @rstoenescu's comparison table:

Command viteConf.command viteConf.mode process.env.NODE_ENV Should alias?
vite serve serve development development
vite serve --mode prd serve prd development
vite serve --mode production serve production development
vite build build production production
vite build --mode prd build prd production
vite build --mode production build production production
vite preview serve production production
vite preview --mode prd serve prd production
vite preview --mode production serve production production
vitest run serve test test
vitest run --mode prd serve prd test
vitest run --mode production serve production test
Command viteConf.command viteConf.mode process.env.NODE_ENV process.env.CI Should alias?
[CI] vitest run serve test test true
[CI] vitest run --mode prd serve prd test true
[CI] vitest run --mode production serve production test true

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.

3 participants