Environment
Application code reads two exported constants from @shadow-js/core:
Application code reads two exported constants from @shadow-js/core:
| Export | Meaning |
|---|---|
isDev |
true in development builds. In production builds the dev-only code (warnings, full error text) is compiled away and this is false. |
isServer |
true in the server build, where effects never run and rendering produces strings. |
import { isDev, isServer } from "@shadow-js/core";
console.log(`isDev=${isDev} isServer=${isServer}`);
isDev=true isServer=falseThe same module compiled and run as the server does:
import { isDev, isServer } from "@shadow-js/core";
console.log(`isDev=${isDev} isServer=${isServer}`);
isDev=true isServer=trueBehind them are four constants the ShadowJS packages are built with: __DEV__, __SERVER__, __TEST__ and
__VERSION__ (declared in types/build-constants.d.ts). The bundler replaces them when the packages are built, so
they do not exist in your app and you cannot rely on them; use isDev and isServer. Each package ships several
builds, and the export conditions pick one:
| Condition (in order checked) | Build | __DEV__ |
__SERVER__ |
|---|---|---|---|
browser + development |
dist/dev |
true | false |
browser + otherwise |
dist/prod (minified) |
false | false |
node, worker, deno or bun + development |
dist/server-dev |
true | true |
node, worker, deno or bun + otherwise |
dist/server (minified) |
false | true |
none of the above, development |
dist/dev |
true | false |
| none of the above | dist/prod |
false | false |
This table is the exports map of @shadow-js/core; @shadow-js/web has the dev and prod builds for its main
entry and the server builds for @shadow-js/web/server. Vite adds the development condition outside production
builds, so vite dev and Vitest get development builds and vite build gets production builds. In development
builds warnings are logged and errors carry their full text; in production builds an error keeps its code and name
(SHADOW_...) and warnings are removed.