如果引入一个框架未内置的插件,需要两个步骤
exports.pluginName = {
enable: true,
package: 'plugin-module-name'
};
这样会有两个问题
一句话说:插件只要安装了,默认就会被加载,开启的话还是在 plugin.js 里,只是不用配置 package 了
具体做法:
目前想到的一个风险就是:应用可能自己安装了一些没用的插件,默认就被开启了,但这个问题可以在开发阶段给与一些提示
新的方案,只是增加了一个 auto load 过程,对于老的方式是兼容的
Translation of this issue:
If you introduce a plugin that does not have a built-in framework, two steps are required
exports.pluginName = {
Enable: true,
Package: 'plugin-module-name'
};
This will have two problems
In a word: The plugin is installed by default. It is enabled by default (how to load it later). If you do not want to open it, the user needs to configure plugin.js enable=false.
specific methods:
One risk that comes to mind at the moment is that the application may install some useless plugins by default and it is enabled by default, but this problem can be given some hints during development.
how about:
https://github.com/eggjs/egg/issues/808
egg-init plugin enable egg-view
egg-init plugin install nunjucks
egg-init plugin list
放到 egg-bin 吧 @atian25
@gxcsoccer 自动加载的方案有点不太可控,提示用户是不会去看的。
是不是可以修改egg插件, 在post-script阶段自动修改plugin.js, 开启插件
@gxcsoccer 自动加载的方案有点不太可控,提示用户是不会去看的。
@dead-horse 或者退一步,安装以后默认不开启,但是不用用户自己去配 package 了,配 package 真的好傻啊
@gxcsoccer 改变用户的安装方式即可: egg-bin plugin install xx 自动安装并配置 plugin.js
@gxcsoccer 改变用户的安装方式即可: egg-bin plugin install xx 自动安装并配置 plugin.js
这是一个选择,和我那个不冲突,像我个人不太喜欢用这种工具,我知道该怎么配 plugin.js,我的方案只是简化了一下配置
但是不用用户自己去配 package 了,配 package 真的好傻啊
意思是在 plugin.js 里面直接写 exports.name = true;,然后自动去寻址么?
意思是在 plugin.js 里面直接写 exports.name = true;,然后自动去寻址么?
就是以前的加载逻辑是依赖 plugin.js 里的 package 或 path 配置来找 plugin,现在改成先就通过 app 和 framework 的 package.json 里的 dependencies 把 plugin 识别出来
这里是不是也要考虑一下,插件版本与框架的对应关系的检测,比如可以借鉴 peerDependencies :
{
"eggPlugin": {
"peerDependencies": ">= 1.5.2 < 2",
"dependencies": [],
"optionalDependencies": [],
"name": "demo"
}
}
否则的话,做到了更容易的加载,冲突也会更严重。
ping @popomore
建议顺便改为 egg.plugin 和 egg.framework 保持同一个节点和风格
建议是默认开启,不要默认关闭,这个模式在laravel5.x的时候已经有一段时间了,社区没有任何问题。
它的处理方式如下(转换成node的模式):
package.json里面添加自己的插件信息,如上面的egg.plugin 。npm install module,在postinstall的hook上创建将自己的信息添加进去(egg可以考虑在start的时候才去创建,php需要在install就去自动发现是因为没有start过程,安装的时候会有提示有哪些包被自动发现了)package.json里面增加egg.plugin.dont-discover将不希望自动发现的插件禁用掉,例如全部禁用:{'egg.plugin.dont-discover':['*']}
--production就可以了。不安装自然也应该没有自动发现的流程。尝试在plugin.js里实现了一下:
测试同时安装egg-rest 和egg-validate ,只自动加载egg-validate。
Most helpful comment
how about:
https://github.com/eggjs/egg/issues/808