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

Support custom mode #12150

Merged
merged 7 commits into from
Oct 17, 2024
Merged

Support custom mode #12150

merged 7 commits into from
Oct 17, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Oct 7, 2024

Changes

Users can know pass custom --mode other than production and development, like staging or anything else etc.

Within Astro, how do we actually tell in we're in dev or prod state now?

For astro dev, it'll always be in the dev state. It's not possible to be in a prod state as it may break existing code, like HMR and stuff (which is also a restriction in Vite)

For astro build, it'll be prod state by default, unless the user passes --devOutput which Astro will then switch to a dev state.

In other parts of the codebase, there's also the concept of runtimeMode which contains this state as either "development" or "production" values only.

Future coding style

If we want to check the prod or dev state, we should no longer rely on mode as that's no longer relevant. We can check via these states instead:

  1. viteResolvedConfig.isProduction
  2. runtimeMode
  3. process.env.NODE_ENV === 'production'
  4. import.meta.env.PROD and import.meta.env.DEV

Testing

Added a new test to verify that it works.

Docs

withastro/docs#9641

Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: 7c9b09e

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 pkg: astro Related to the core `astro` package (scope) docs pr semver: minor Change triggers a `minor` release labels Oct 7, 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.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I really like the fact that we internally create a distinction between "command" and "mode"

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.

Looks great @bluwy ! I'm not sure if it was intentional, but devOutput was kind of glossed over so I added a sentence to introduce it as a new thing. Some suggestions for your consideration!

.changeset/sixty-coins-worry.md Outdated Show resolved Hide resolved
.changeset/sixty-coins-worry.md Outdated Show resolved Hide resolved
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
@bluwy
Copy link
Member Author

bluwy commented Oct 16, 2024

Looks great! I didn't document --devOutput a lot as it's not a very common thing needed for most people. But happy to emphasize that a bit too.

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.

🥳

@bluwy bluwy merged commit 93351bc into next Oct 17, 2024
3 checks passed
@bluwy bluwy deleted the plt-2220-custom-mode branch October 17, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants