-
Notifications
You must be signed in to change notification settings - Fork 3
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
macros should not throw when running outside of vite #42
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 65fd649 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
Makes sense!
Thinking more about this... I think a better API would be something like: // script.ts
import { setEnv } from "vite-env-only/macros"
setEnv("server")
// in the future could even set compat for multiple envs:
// `setEnv("server", "client")`
// seems weird now, but with Vite v6 it fits right in
// ..run code that depends on macros.. where The benefit here is that you would get an error that points directly to the offending code wrapped by the macro as soon as that definition is accessed. Whereas the current approach only gives you errors when you happen to access things that aren't defined in the env runtime and with stacktraces that point deep into your deps. |
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.
What's the goal with the setEnv
direction? To me the main goal is to provide feedback for those who haven't configured the Vite plugin properly within a Vite context. What's the use case outside of Vite?
The issue with relying solely on the internal |
Fixes #19