API 索引

svrx(option)

获得 svrx 实例

Usage

const svrx = require('@svrx/svrx');

const server = svrx({
  port: 8002
});

Param

Return

Svrx 实例

server.start()

启动 Svrx

Usage

server.start().then(port => {
  console.log(port);
});

Return

Promise

server.close()

Usage

server.close().then(() => {
  console.log('Svrx has closed');
});

Param

Return

Promise

server.reload()

主动刷新浏览器

Usage

server.reload();

server.on

绑定事件

内置事件

1. ready

在服务启动时触发

server.on('ready', port => {});

2. plugin

在 build 插件后触发,与插件开发的hook.onCreate钩子接受同样的参数,请参考插件开发指南

server.on('plugin', async ({io, events, config, router, injector, logger, middleware }=>{
    // you logic here
}))

3. file:change

在文件变化后触发(必须 livereload 为 true)

server.off

解绑事件

server.on('file:change', handler);
server.off('file:change', handler);

server.emit

server.emit('custom-event', { param1: 1 });
Copyright © 2019, NetEase, Inc. all right reserved,powered by GitbookFile Modify: 2019-12-18 15:48:24

results matching ""

    No results matching ""