0.1.0 • Published 6 years ago

egg-extra-loader v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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();

License

MIT

0.1.4

6 years ago

0.1.3

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago