docs: correct README (#3)
Stub class like service/grpc etc.. for develop purpose.
$ npm i egg-development-stub --save-dev
// {app_root}/config/plugin.local.js exports.stub = { enable: true, package: 'egg-development-stub', };
Only use at not-production mode, will skip to prod. Recommand to hook at plugin.local.js.
prod
plugin.local.js
Put your stub file at app/stub/{type}/**/*.js.
app/stub/{type}/**/*.js
egg-example └── app ├── service │ └── test.js └── stub └── service └── test.js
Support stub service/grpc by default, you can config mapping to others.
service/grpc
mapping
// {app_root}/config/config.default.js config.stub = { // stub files root dir // dir: path.join(appInfo.baseDir, 'app/stub'), // stub target mapping // mapping: { // service: 'serviceClasses', // grpc: 'grpcClasses', // }, };
see config/config.default.js for more detail.
Origin Service:
// app/service/test.js module.exports = app => { class TestService extends app.Service { echo() { return 'origin fn'; } } return TestService; };
In general, you can stub with commonjs exports:
// app/stub/service/test.js exports.echo = () => 'stub fn'; // or module.exports = app => { return { echo: () => app.config.name; } }
Advanced usage: stub with sub class, so you can custom your logic.
// app/stub/service/test.js module.exports = (app, TargetClass) => { return StubClass extends TargetClass { echo() { return 'stub: ' + super.echo(); } } }
Note: SubClass mode don’t support origin service use commonjs style.
Please open an issue here.
MIT
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
egg-development-stub
Stub class like service/grpc etc.. for develop purpose.
Install
Usage
Configuration
Put your stub file at
app/stub/{type}/**/*.js.Support stub
service/grpcby default, you can configmappingto others.see config/config.default.js for more detail.
Example
Origin Service:
In general, you can stub with commonjs exports:
Advanced usage: stub with sub class, so you can custom your logic.
Questions & Suggestions
Please open an issue here.
License
MIT