Skip to content

Env

Zova exposes env variables on the special process.env object, which are statically replaced at build time

meta & .env file

Zova uses dotenv to load additional environment variables from the following files in the directory env:

txt
.env                # loaded in all cases
.env.mine           # loaded in all cases, ignored by git
.env.[meta]         # only loaded in specified condition
.env.[meta].mine    # only loaded in specified condition, ignored by git
  • [meta] can be any combination of the following three field values
NameDescription
mode'development' | 'production' | string;
flavor'web' | 'app' | string;
appMode'spa' | 'ssr' | 'pwa' | 'cordova' | 'capacitor' | 'electron' | 'bex' | string | undefined;

mode

bash
$ npm run dev     # mode is 'development'
$ npm run build   # mode is 'production'

flavor

The flavor variable value can be passed in through the command line. The default value is app

bash
$ npm run [dev/build]                # flavor is 'app'
$ FLAVOR=app npm run [dev/build]     # flavor is 'app'
$ FLAVOR=web npm run [dev/build]     # flavor is 'web'

appMode

The appMode variable value can be passed in through the command line. The default value is spa

bash
$ npm run [dev/build]                # appMode is 'spa'
$ APPMODE=spa npm run [dev/build]    # appMode is 'spa'
$ APPMODE=ssr npm run [dev/build]    # appMode is 'ssr'

For example

Execute npm run dev on the command line, then the corresponding meta variable values are:

NameValue
mode'development'
flavor'app'
appMode'spa'

The system will automatically load the environment variables in the following files and merge them:

txt
.env
.env.mine
.env.app
.env.app.mine
.env.app.development
.env.app.development.mine
.env.app.development.spa
.env.app.development.spa.mine

Built-in env variables

To further achieve out-of-box functionality, Zova provides several built-in env variables:

meta

NameDescription
META_MODEmode
META_FLAVORflavor
META_APP_MODEappMode
NODE_ENVequal META_MODE

Dev server

NameDescription
DEV_SERVER_HOSTDev server host Vite: server.host
DEV_SERVER_PORTDev server port

App

NameDescription
APP_SERVERWhether to run on the server
APP_ROUTER_MODEVue Router: History Modes
APP_ROUTER_BASEVue Router: base
APP_PUBLIC_PATHVite: Public Base Path
APP_NAMEApp Name
APP_TITLEApp Title
APP_VERSIONApp Version

Suite/Module

NameDescription
PROJECT_DISABLED_MODULESList of disabled modules
PROJECT_DISABLED_SUITESList of disabled suites

API

NameDescription
API_BASE_URL
API_PREFIX

src/front/config/config/config.ts

typescript
export default function (_meta: ZovaConfigMeta) {
  const config: ZovaConfigOptional = {
    base: {},
    api: {
      baseURL: process.env.API_BASE_URL,
      prefix: process.env.API_PREFIX,
    },
    layout: {},
  };
  return config;
}

src/suite/a-home/modules/home-api/src/bean/store.api.ts

typescript
export class StoreApi {
  private [SymbolApi]: AxiosInstance;

  protected async __init__() {
    const baseURL = `${this.app.config.api.baseURL || ''}${this.app.config.api.prefix || ''}/`;
    this[SymbolApi] = markRaw(axios.create({ baseURL }));
  }
}

Proxy

NameDescription
PROXY_API_ENABLEDWhether to enable proxy: Vite: server.proxy
PROXY_API_BASE_URLproxy target
PROXY_API_PREFIXproxy key

Mock

See: Mock

Released under the MIT License.