Skip to content

vite-plugin incorrectly aliases production builds with alternative mode names #17859

@athisun

Description

@athisun

What happened?

Our team uses abbreviated build mode names vite build --mode=prd, but this line

if (viteMode !== 'production') {
causes the quasar package to be aliased unless the mode is strictly named "production". This causes production builds to include the dev file, hugely increasing the bundle size.

As noted by https://vite.dev/guide/env-and-mode.html#node-env-and-modes, process.env.NODE_ENV is the controlling variable driving the value of import.meta.env.PROD.

Vite builds (with any mode name) default to NODE_ENV=production, and is expected to be overridden in the mode-linked .env.mode files. Users can therefore define multiple production modes, or the 'production' mode can be renamed.

What did you expect to happen?

Quasar package should not be aliased in builds with NODE_ENV=production. A solution could look like either:

  1. Production mode should be checked via process.env.NODE_ENV === 'production', not envConfig.mode === 'production'.
  2. Use envConfig.command !== 'build' instead of envConfig.mode == 'production'

Reproduction URL

https://stackblitz.com/edit/vitejs-vite-rh8eamlj

How to reproduce?

  1. Run vite build --mode prd (or npm run build:prd in the stackblitz).
  2. Compare envConfig.mode to NODE_ENV: mode: prd NODE_ENV: production.
  3. Check bundle size (e.g. npx vite-bundle-visualizer) to observe dist/quasar.client.js being included.

Flavour

Vite Plugin (@quasar/vite-plugin)

Areas

Plugins (quasar)

Platforms/Browsers

No response

Quasar info output

Relevant log output

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions