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

Add "--viteMode" CLI flag for dev and build command #10871

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

acupofspirt
Copy link

@acupofspirt acupofspirt commented Apr 24, 2024

Changes

What's inside?

This PR adds a new CLI flag --viteMode for dev and build commands.
The flag value will be passed to the resulting Vite config, allowing us to load different .env.[mode] files. According to Vite documentation, the flag value will also be reflected in import.meta.env.MODE.

What about the existing --mode flag?

It works only for the build command and serves a different purpose than the new flag. --mode should have been called --isProd or --isDev because it sets the internal mode variable, which is heavily used in the codebase to check for production/development mode. Also, it has never been documented, so it can't be considered a public API.

Backward compatibility

As a new feature, it will be a minor change.

Testing

Unit tests were added.

Docs

withastro/docs#8016

/cc @withastro/maintainers-docs

Copy link

changeset-bot bot commented Apr 24, 2024

🦋 Changeset detected

Latest commit: 40a60c9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 24, 2024
@bluwy
Copy link
Member

bluwy commented Apr 25, 2024

There's a past PR for this that was closed #6735

EDIT: Well I just noticed that you linked #4850, so we already somewhat support this mode. I don't think supporting custom modes will work everywhere in Astro, but if this is to only align with #4850 then I guess it's fine for now.

@acupofspirt
Copy link
Author

@bluwy, you are right. I did it just to get this functional parity between dev and build commands.

@ematipico
Copy link
Member

There's a past PR for this that was closed #6735

EDIT: Well I just noticed that you linked #4850, so we already somewhat support this mode. I don't think supporting custom modes will work everywhere in Astro, but if this is to only align with #4850 then I guess it's fine for now.

If what you say is correct, maybe we should add some documentation (considering that we don't have it) and explain expectations. Like, that it won't work everywhere.

@github-actions github-actions bot added pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) docs pr A PR that includes documentation for review labels Apr 25, 2024
@acupofspirt acupofspirt changed the title Respect "--mode" flag when running dev command Add "--viteMode" CLI flag for dev and build command Apr 25, 2024
@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Apr 25, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@acupofspirt
Copy link
Author

@bluwy @ematipico After a more thorough analysis of the code base I decided to use a new flag instead of the existing one. It will be a cleaner and safer solution. It won't affect internal Astro logic (I've checked all possible places). It just passes the flag value to Vite config.
I've updated the PR description and forcepushed new changes. Later I'll open a PR for the docs.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick changeset edit from docs, and in case wanted, giving you permission to "sell" this feature a little more! 😄

.changeset/bright-zebras-end.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr A PR that includes documentation for review pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants