Is it possible to run a different build command based on whether you're doing `wrangler dev/deploy`

I'm using workers-rs, and my wasm build takes a very long time in release mode, to the point where it's too slow for rapid iteration in local development. It's much better if I build in dev mode. The default build command in wrangler.toml is:
[build]
command = "cargo install -q worker-build && worker-build --release"
[build]
command = "cargo install -q worker-build && worker-build --release"
I can change the --release to --dev, which results in much faster build times, but then I might forget about it and accidentally upload an unoptimized .wasm file to production. I have been experimenting to try to figure out if there's a way to know whether wrangler is being run in dev or deploy modes inside the build command. I was hoping I could read an environment variable and change the behavior of my build command, but I can't see any environment variables that change based on dev or deploy. I've noticed that wrangler apparently has some support for reading .env files (there is an -e parameter to the wrangler dev cli), but I have not been able to get that to work -- I don't see any custom defined environment variables inside a build command environment (tested by changing my build command to set).
1 Reply
radix
radix7mo ago
Unfortunately, I haven't been able to figure out a way to do something conditional automatically based on whether dev or deploy is being run, but I solved this by just implementing a custom command that checks my own custom environment variable and I only set that variable when I'm running wrangler dev, e.g. WORKER_MODE="--dev" wrangler dev