-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve env var handling in SSR #9637
Conversation
🦋 Changeset detectedLatest commit: c9e2cd9 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 |
privateEnv.SITE = astroConfig.site ? JSON.stringify(astroConfig.site) : 'undefined'; | ||
privateEnv.SSR = JSON.stringify(true); | ||
privateEnv.BASE_URL = astroConfig.base ? JSON.stringify(astroConfig.base) : 'undefined'; | ||
privateEnv.ASSETS_PREFIX = astroConfig.build.assetsPrefix | ||
? JSON.stringify(astroConfig.build.assetsPrefix) | ||
: 'undefined'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to re-specify these here as Vite will already handle them. If we specify them here, we'd do a plain string replacement instead, which is less accurate than Vite's implementation.
@@ -308,3 +308,7 @@ function isCommonNotAstro(dep: string): boolean { | |||
) | |||
); | |||
} | |||
|
|||
function stringifyForDefine(value: string | undefined): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be stringifyOrDefine
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is "For" since we're stringifying the value
for the define
config passed to Vite.
Changes
Some env var replacement can be relayed to Vite to replace instead, which is more accurate as we're using plain string replacements. I'm currently working on improving Astro's env replacement too and notice this stop gap improvement.
Testing
Existing env vars tests should pass.
Docs
n/a. internal refactor.