@ddn/core
TypeScript icon, indicating that this package has built-in type declarations

2.5.0 • Public • Published

@DDN/core

用于对 DDN 区块链 相关的配置等相关的基本操作,让系统支持 .ddnrc.js、constants.js 等根据环境不同的配置文件

配置文件

DDN 允许在 .ddnrc.t|jsconfig/config.jsonconfig/config.t|js(五选一,.ddnrc.t|js 优先),以及基于该配置的 constants.t|js, config/constants.t|js(四选一,必须有一个,constants.t|js优先) 中进行配置,支持 ES6 语法。

注意:不要将上述配置混合使用,按照优先级,有且只能有一个

为简化说明,后续文档里只会出现 .ddnrc.js

比如:

// .ddnrc.js
export default {
  publicPath: 'http://bar.com/foo',
  assets: [
    ['asset-aob', {
      assets: true,
    }],
  ],
};

具体配置项详见配置

优先级

总的原则是,NODE_ENV区分生产环境、开发环境,DDN_ENV区分物理环境(文件)。生产环境下,*.mainnet.*文件优先,其他环境下,优先级为 *.local.* > .{DDN_ENV}. > *.testnet.*

  • 1、production: constants.mainnet.* [生产环境下最优先]
  • 2、local: constants.local.*
  • 3、custom: constants.{DdnEnv}.*
  • 4、development: constants.testnet.*;

本地配置

.ddnrc.local.js

.ddnrc.local.js 是本地的配置文件,不要提交到 git,所以通常需要配置到 .gitignore

.ddnrc.local.js 默认有效。如果存在,会自动覆盖 .ddnrc.js 的同名配置,再返回。所以,你如果有个性化的本地配置,可以添加该文件,从而避免对正式配置文件的污染。

环境变量

1. NODE_ENV

程序默认是开发环境,即:非生产环境,.ddnrc.local.js.ddnrc.testnet.js 起作用,且前者覆盖后者,.ddnrc.mainnet.js 不起作用。

如果设置 NODE_ENV=production ,程序将运行在生产环境下,.ddnrc.local.js.ddnrc.testnet.js 将被.ddnrc.mainnet.js自动覆盖。

2. DDN_ENV

如果需要临时或定制化的环境配置,可以通过环境变量 DDN_ENV 区分,例如:针对不同物理环境(比如:cloud, custom)来指定配置。

举个例子,

// .ddnrc.js
export default { a: 1, b: 2 };

// DDN_ENV=cloud -> .ddnrc.cloud.js 
export default { b: 'cloud', c: 'cloud' };

// .ddnrc.local.js
export default { c: 'local' };

不指定 DDN_ENV 时,拿到的配置是:

{
  a: 1,
  b: 2,
  c: 'local',
}

指定 DDN_ENV=cloud 时,拿到的配置是:

{
  a: 1,
  b: 'cloud',
  c: 'local',
}

Readme

Keywords

Package Sidebar

Install

npm i @ddn/core

Weekly Downloads

30

Version

2.5.0

License

AGPL 3.0

Unpacked Size

28.9 kB

Total Files

10

Last publish

Collaborators

  • imfly
  • evanlai
  • bjtailor