Skip to content

Config

meta & config file

Zova loads config files from the src/front/config/config directory. File loading based on meta conditions is also supported. For specific rules, see: meta & .env file

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 configuration in the following files and merge them:

txt
config.ts
config.mine.ts
config.app.ts
config.app.mine.ts
config.app.development.ts
config.app.development.mine.ts
config.app.development.spa.ts
config.app.development.spa.mine.ts

Use global config

The global config object can be obtained directly through this.app.config in any bean instance

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 }));
  }
}

Use module config

Modules can individually provide their own config configuration, which can be obtained through the Scope instance. See: Config

Override module config

You can use project-level config to override module-level config, see: Config

The relationship between env and config

Some variables exist in both env and config. The basic logic is as follows:

  1. Configure the value of the variable in env
  2. Let the value in config equal the value in env
  3. Prioritize using variable values through config in code
  4. If you need to use the build-time tree shaking capability, use the value of the variable through process.env.xxx

Variable comparison table

Variables in envVariables in config
META_MODEmeta.mode
META_FLAVORmeta.flavor
META_APP_MODEmeta.appMode
APP_SERVERenv.appServer
APP_ROUTER_MODEenv.appRouterMode
APP_ROUTER_BASEenv.appRouterBase
APP_PUBLIC_PATHenv.appPublicPath
APP_NAMEenv.appName
APP_TITLEenv.appTitle
APP_VERSIONenv.appVersion
API_BASE_URLapi.baseURL
API_PREFIXapi.prefix

Released under the MIT License.