Different config for dev and production in Stati

getEnv() knows which command is running. NODE_ENV doesn't.

SNP 135 #529 Filed stati typescript

typescript
// stati.config.ts
import { defineConfig, getEnv } from '@stati/core';

// 'production' in stati build, 'development' in stati dev
const production = getEnv() === 'production';

export default defineConfig({
  site: {
    title: 'My site',
    baseUrl: process.env.SITE_URL ?? (production ? 'https://example.com' : 'http://localhost:3000'),
  },
  seo: {
    // SEO warnings while I work on the site
    debug: !production,
  },
});
  • Stati never sets NODE_ENV. A config that checks process.env.NODE_ENV === 'production' takes the development branch in a plain stati build, unless the script sets the variable itself.
  • For more targets than two, read a variable of your own: SITE_URL=https://staging.example.com npm run build.
  • Stati only looks for stati.config.ts, .js or .mjs in the folder it runs in, so a separate stati.staging.ts is never read. One config, switched by variables.
  • The dev server reads the config once, when it starts. Restart it after changing the config or the variables it reads.

In the Stati docs: Multi-environment configuration and Environment configuration.