Skip to content

VitePress should mimic Vite's --mode flag when running "vitepress build" #2692

@MilosRandelovic

Description

@MilosRandelovic

Is your feature request related to a problem? Please describe.

When building with Vite and using multiple .env.* files, there is a mode flag which essentially tells Vite to load the .env.<mode> file. By default, this flag is set to production when running the build command.

Let's say I have 3 .env.* files:

  • .env - my default localhost dev env file
  • .env.uat - the env file I wish to use when deploying to UAT
  • .env.prod - the env file I wish to use when deploying to PROD

Having a Vite app, in dev mode (vite dev) the default .env file is loaded, and when running build I can pass the mode I wish (e.g. vite build --mode uat), usually coming as an arg from my build config.

What happens when using VitePress?

VitePress takes only the default Vite behaviour, which is to set the mode to production when running vitepress build. Passing the --mode flag has no effect. The development server (vitepress dev) loads the default .env file correctly (.env).

Describe the solution you'd like

VitePress should honour the --mode flag in the same manner as Vite does.

Describe alternatives you've considered

My current workaround is to manually rename different .env.* files to .env.production before vitepress build, even if I am not building for a production environment. This works, but is not ideal, and certainly not consistent with my other Vite/Vue apps.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildRelated to the build systemhas-workaroundHas workaround, low prioritystale

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions