Skip to content

基础 config 文件

bash
# 位置
./electron/config/

# 说明
config.default.js // 默认配置文件,开发环境和生产环境都会加载
config.local.js   // 开发环境配置文件,追加和覆盖default配置文件
config.prod.js    // 生产环境配置文件,追加和覆盖default配置文件

属性说明

开发者工具

javascript
openDevTools: boolean | object;

// 说明
false, // false: 不开启,true: 开启

{
  mode: 'detach', // left, right, bottom, undocked, detach
  activate: true, // 是否将打开的开发者工具窗口置于前台
  title: '', //  A title for the DevTools window (only in undocked or detach mode).
}

单应用

javascript
singleLock = true; // 只能打开一个应用实例

主窗口

javascript
// 更多属性,见文档:https://www.electronjs.org/zh/docs/latest/api/browser-window#new-browserwindowoptions
windowsOption = {
  title: 'EE框架', // 软件顶部或左上角名称(会被 html中的 title标签覆盖)
  width: 980, // 软件窗口宽度
  height: 650, // 软件窗口高度
  minWidth: 800, // 软件窗口最小宽度
  minHeight: 650, // 软件窗口最小高度
  webPreferences: {
    //webSecurity: false, // 如果需要跨域,请打开注释
    contextIsolation: false, // 设置此项为false后,才可在渲染进程中使用electron api
    nodeIntegration: true, // node模块
    //preload: path.join(getBaseDir(), 'preload', 'bridge.js'),
  },
  frame: true,
  show: true, 
	icon: path.join(getBaseDir(), 'public', 'images', 'logo-32.png'),
};

业务日志

javascript
logger = {
  /** 日志级别:trace < debug < info < warn < error < fatal */
  level: 'info',
  /** 开发环境是否使用美化格式输出 */
  prettyPrint: true,
  /** 日志文件名日期格式 */
  dateFormat: 'yyyy-MM-dd',
  /** 应用日志文件名 */
  appLogName: 'ee.log',
  /** 框架核心日志文件名 */
  coreLogName: 'ee-core.log',
  /** 错误日志文件名 */
  errorLogName: 'ee-error.log',
  /** 日志轮转策略:day(按天),hour(按小时) */
  rotator: 'day',
  /** 需要脱敏的字段路径列表 */
  redact: [],
  /** 脱敏替换值 */
  redactCensor: '[Redacted]',
  /** 是否包含时间戳 */
  timestamp: true,
  /** 日志时间戳的 IANA 时区(文件 JSON 日志);'UTC' 或如 'Asia/Shanghai' */
  timezone: 'UTC',
  /** pino 日志器名称 */
  name: 'ee',
  /** 单个日志文件最大大小 */
  maxSize: '100m',
  /** pino 序列化器 */
  serializers: {},
  /** 自定义日志级别 */
  customLevels: {},
  /** 对象序列化深度限制 */
  depthLimit: 5,
  /** 安全模式:日志写入失败时不抛出异常 */
  safe: true,
}

远程web地址

javascript
remoteUrl = {
  enable: false, // 是否启用
  url: 'http://electron-egg.kaka996.com/' // Any web url
};

内置socket服务

javascript
# 第三方软件,可通过socket-client监听端口,与ee框架通信
socketServer = {
  enable: false, // 是否启用
  port: 7070, // 默认端口
  isDynamic: false, // 如果值为false,框架默认使用port端口(如果默认端口被使用,则随机获取一个);如果为true,默认端口无效,框架随机生成
  path: "/socket.io/", // 默认路径名称
  connectTimeout: 45000, // 客户端连接超时时间
  pingTimeout: 30000, // 心跳检测超时时间
  pingInterval: 25000, // 心跳检测间隔
  maxHttpBufferSize: 1e8, // 每条消息的数据最大值 1M
  transports: ["polling", "websocket"], // http轮询和websocket
  cors: {
    origin: true, // http协议时,要设置允许跨域
  },
  channel: 'socket-channel'   // 自定义通道名称,默认socket-channel
};

内置http服务

javascript
# 可在前端、浏览器、终端命令中,访问EE程序  
httpServer = {
  enable: false, // 是否启用
  https: {
    enable: false, 
    key: '/public/ssl/localhost+1.key', // key文件
    cert: '/public/ssl/localhost+1.pem' // cert文件
  },
  host: '127.0.0.1',
  port: 7071, // 默认端口(如果端口被使用,则随机获取一个)
  cors: {
    origin: "*" // 跨域
  },
  body: {
    multipart: true,
    formidable: {
      keepExtensions: true
    }
  },
  filterRequest: {
    uris:  [
      'favicon.ico' // 要过滤的请求uri
    ],
    returnData: '' // 任意数据类型
  }
};

主进程

javascript
mainServer = {
  // 协议:file://
  protocol: 'file://',
  // 前端资源入口文件
  indexPath: '/public/dist/index.html',
  // 兼容electron参数
  // https://www.electronjs.org/zh/docs/latest/api/browser-window#winloadurlurl-options
  options: {},
  // 加载一个loading页,一般不用开启
  loadingPage: '/public/html/loading.html',
  // 接管。如果想加载一个go web程序,来替代 protocol
  takeover: 'go',
  channelSeparator: '/', // 通信频道路径分割符
};

跨语言服务

运行其它语言的可执行程序。

javascript
cross = {
  // 自定义服务名
  go: {
    // 是否开启
    enable: true,
    // 可执行程序名
    name: 'goapp',
    // 参数
    args: ['--port=7073'],
    // 可执行程序退出时,是否退出整个桌面程序
    appExit: true,
  }
};

异常捕获

进程捕获异常后,是否退出。

javascript
exception = {
  // 主进程
  mainExit: false,
  // jobs 子进程
  childExit: false,
};

jobs 任务

javascript
jobs = {
  // 是否 打印/记录 进程间通信的消息log
  messageLog: true
};