-
Notifications
You must be signed in to change notification settings - Fork 204
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
[Feature Request] Set os environment variable during dev #65
Comments
Hey! 👋 This definitely sounds useful for build scripts. Wondering if it's also worth setting a |
Honestly think both would be great. Adding it to the worker context, would only work in some cases. So probably well worth documenting where you can use it. If you can point me in the right direction, I can surely help here with a PR 🚀 |
Hey! 👋 The first pre-release of Miniflare 2 has just been released, including both a |
Loving miniflare, tx! This was a helpful thread for me… What is your recommended usage? I was confused by:
…as when I run webpack 5.64.2 compiled successfully in 827 ms
✨ Build completed successfully!
Error: Something went wrong with the request to Cloudflare...
Uncaught ReferenceError: MINIFLARE is not defined
at line 435
at line 449
at line 451
[API code: 10021] My solution is importing the following declare const MINIFLARE: boolean | number
/**
* DEV is true if we're running inside miniflare.
*
* Miniflare sets MINIFLARE=true (or 1?), but it's not available in to `wrangler publish`
*
* See https://github.com/cloudflare/miniflare/issues/65#issuecomment-952828243
*/
export const DEV = typeof MINIFLARE !== 'undefined'
export const PROD = !DEV I'm on |
Hey! 👋 Depends on where you're using it. If it's in your actual worker code... if (globalThis.MINIFLARE) {
// Do something when running in Miniflare
} else {
// Do something when running in production
} Note the If it's in a custom Node.js build script, say if(process.env.MINIFLARE) {
// Do something when building for Miniflare
} else {
// Do something when building for production
} |
Heaps cleaner, thanks! 🙏
That's me - I'm loading different data from staging 👍 I'm using https://github.com/cloudflare/worker-typescript-template, and when I referenced
…which I resolved by added the following to my src/global.d.ts: declare global {
/** globalThis.MINIFLARE is true if we're in running in miniflare in dev */
var MINIFLARE: boolean | undefined
}
export {} Thanks for your help! |
When running
miniflare
from cli (or perhaps through node api) set aprocess.env.MINIFLARE = true
header.Why?
When using build tools like esbuild or like id like to run slightly different code during my local dev time, than the worker running on the real platform.
Currently im
env MINIFLARE=1 miniflare
— but be awesome to have this first-class.The text was updated successfully, but these errors were encountered: