egg-development-stub
Stub class like service/grpc etc.. for develop purpose.
Install
$ npm i egg-development-stub --save-dev
Usage
// {app_root}/config/plugin.local.jsexportsstub = enable: true package: 'egg-development-stub';
Only use at not-production mode, will skip to
prod
. Recommand to hook atplugin.local.js
.
Configuration
Put your stub file at 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.
// {app_root}/config/config.default.jsconfigstub = // stub files root dir // dir: path.join(appInfo.baseDir, 'stub'), // stub target mapping // mapping: { // service: 'serviceClasses', // grpc: 'grpcClasses', // },;
see config/config.default.js for more detail.
Example
Origin Service:
// app/service/test.jsmodule { Service { return 'origin fn'; } return TestService;};
In general, you can stub with commonjs exports:
// app/stub/service/test.jsexports 'stub fn'; // ormodule { return appconfigname; }
Advanced usage: stub with sub class, so you can custom your logic.
// app/stub/service/test.jsmodule { return StubClass extends TargetClass { return 'stub: ' + super; } }
Note: SubClass mode don't support origin service use commonjs style.
Questions & Suggestions
Please open an issue here.