-
-
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
fix: import.meta.env.BASE_URL will be '/' in client loaded component on dev mode #4886
Conversation
🦋 Changeset detectedLatest commit: e227d9f 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 |
@@ -52,6 +52,9 @@ export default async function dev( | |||
optimizeDeps: { | |||
include: rendererClientEntries, | |||
}, | |||
define: { | |||
'import.meta.env.BASE_URL': settings.config.base ? `'${settings.config.base}'` : '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.
Would it be the same as the following?
settings.config.base || '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.
If base is not set, would it not show /undefined/ instead of / in that case here? Since you added undefined in strings?
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.
Refer to Vite Define docs: https://vitejs.dev/config/shared-options.html#define
and https://github.com/withastro/astro/blob/main/packages/astro/src/core/create-vite.ts#L96
We do need to use strings.
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.
If base is not set, it would show /
in that case here.
What's more, settings.config.base
and '${settings.config.base}'
are different, notice the single quotes
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.
@yuhang-dong yup, now I see it. Thanks for the accurate pointers!
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.
LGTM
I don't think I'm eligible to post a 'approved' |
Changes
Hi, I have found that
import.meta.env.BASE_URL
will be set/
in client loaded component on dev mode.And after searching from issues, I found #3567 describe the same situation.
In the conversion, I have found pr#3955 just fix prod mode.
You can visit the below link to see
import.meta.env.BASE_URL
will be set '/' in client loaded component on dev mode:https://stackblitz.com/edit/github-vhnc6s-13dn4n?file=src%2Fpages%2Findex.astro
So, I defined the
import.meta.env.BASE_URL
tosetting.config.base
.Testing
This situation need e2e test, so I added it on
[packages/astro/e2e/astro-envs.test.js]
Docs
N/A