0.1.0 • Published 6 years ago
egg-extra-loader v0.1.0
egg-extra-loader
提供更加方便的loader
扩展。
Install
$ npm i egg-extra-loader --save
Usage
// {app_root}/config/plugin.js
exports.extraLoader = {
enable: true,
package: 'egg-extra-loader',
};
Configuration
// {app_root}/config/config.default.js
exports.extraLoader = {
base: 'app',
toBind: ['app','ctx'],
defaultOptions: {
call: false
},
bindings: [
{
dir: 'love',
property: 'love',
toBind: ['ctx']
},
{
dir: 'models',
property: 'model',
toBind: ['app'],
options: {
call: true
}
}
]
};
see config/config.default.js for more detail.
Example
// app/love/love.js
module.exports = {
sayLove(){
console.log("I love you")
}
}
// app/models/hello.js
module.exports = app => {
return {
sayHello(){
console.log("hello")
}
}
}
// app.js
const ctx = app.createAnonymousContext();
ctx.love.love.sayLove();
app.model.hello.sayHello();