Skip to content

Config

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

meta & config file

Vona loads config files from the src/backend/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'dev'
flavor'normal'

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

txt
config.ts
config.normal.ts
config.normal.dev.ts
config.mine.ts
config.normal.mine.ts
config.normal.dev.mine.ts

Use global config

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

typescript
@Service()
export class ServiceDatabase extends BeanBase {
  get configDatabase() {
    return this.app.config.database;
  }
}

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
process.env.META_MODEapp.config.meta.mode
process.env.META_FLAVORapp.config.meta.flavor

Released under the MIT License.