Skip to content

Env

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

Zova loads environment files based on multi-dimensional variables, providing a more flexible configuration mechanism and supporting more complex business scenarios

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.[meta]         # only loaded in specified condition
.env.mine           # loaded in all cases, ignored by git
.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'front' | 'admin' | string;
appMode'spa' | 'ssr' | 'pwa' | 'cordova' | 'capacitor' | 'electron' | 'bex' | string

npm scripts

Corresponding to the multi-dimensional variables, the command line script is also divided into three parts, such as:

bash
$ npm run dev:ssr:admin
$ npm run build:ssr:admin

For convenience, we can set the most commonly used scripts as aliases, for example:

json
"scripts": {
  "dev": "npm run dev:ssr:admin",
  "build": "npm run build:ssr:admin",
  "preview": "npm run preview:ssr",
  "dev:ssr:admin": "npm run prerun && quasar dev --mode ssr --flavor admin",
  "build:ssr:admin": "npm run prerun && quasar build --mode ssr --flavor admin",
  "preview:ssr": "concurrently \"cd ./distMockServer && node index.js\" \"node ./dist/ssr/index.js\"",
},

For example

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

NameValue
mode'development'
flavor'admin'
appMode'ssr'

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

txt
.env
.env.admin
.env.admin.development
.env.admin.development.ssr
.env.mine
.env.admin.mine
.env.admin.development.mine
.env.admin.development.ssr.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

App

NameDescription
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

Dev server

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

Build

NameDescription
BUILD_OUTDIRSpecify the output directory
BUILD_MINIFYWhether to enable minify
BUILD_ANALYZEWhether to display the analyze info

Suite/Module

NameDescription
PROJECT_DISABLED_MODULESList of disabled modules
PROJECT_DISABLED_SUITESList of disabled suites

API

NameDescription
API_BASE_URL
API_PREFIX
API_JWTWhether to enable JWT

PINIA

NameDescription
PINIA_ENABLEDWhether to enable Pinia

Proxy

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

SSR

See: SSR

Mock

See: Mock

Dynamic environment variables

The following are the environment variables set according to the runtime environment:

NameDescription
SSRIf SSR mode
DEVIf Development
PRODIf Production
CLIENTIf Client
SERVERIf Server

Released under the MIT License.