Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] customLoader #3480

Closed
4 of 7 tasks
popomore opened this issue Feb 20, 2019 · 9 comments
Closed
4 of 7 tasks

[RFC] customLoader #3480

popomore opened this issue Feb 20, 2019 · 9 comments
Assignees

Comments

@popomore
Copy link
Member

popomore commented Feb 20, 2019

背景

Egg 支持自定义 loader,通过 app.loader 的 API 可以自定义加载某个目录的文件到 app 或 ctx。

但是通过 API 调用比较麻烦

  1. 非声明式的,使用不友好
  2. loader 属于内部 API,透出重构成本高
  3. 如果使用 ts 还得重新定义一遍

思路

config.default.js 增加 customLoader 的配置,不需要再使用 API

exports.customLoader = {
  service: {
    directory: 'app/service',
    inject: 'ctx', // or app
    loadunit: false, // 是否加载框架和插件目录
    // other loads options
  },
};

egg-ts-helper 也可以读这个配置来生成 typing

在 didLoad 加载自定义 loader

跟进

@atian25
Copy link
Member

atian25 commented Feb 20, 2019

在哪个生命周期加载?

@popomore
Copy link
Member Author

didLoad 吧

@popomore
Copy link
Member Author

有个问题,需要区分 app/agent 吗,一般都在 app 里面

@whxaxes
Copy link
Member

whxaxes commented Feb 21, 2019

可以区分一下吧,inject 里可以填 app 或者 agent ?

@whxaxes
Copy link
Member

whxaxes commented Feb 21, 2019

存不存在这种场景,需要同时 load 到 app 和 agent 上?那这样 inject 是否也可以支持传个数组?

popomore added a commit that referenced this issue Feb 21, 2019
@popomore
Copy link
Member Author

inject 只有 app/ctx,如果要支持可以加个 type

@popomore
Copy link
Member Author

popomore commented Mar 6, 2019

eggjs/mock#95

popomore added a commit that referenced this issue Mar 7, 2019
popomore pushed a commit that referenced this issue Mar 7, 2019
feat: support customLoader (#3484)

#3480
@whxaxes
Copy link
Member

whxaxes commented Mar 8, 2019

eggjs/egg-ts-helper#41

@skyitachi
Copy link

great work

@popomore popomore closed this as completed Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants