opti: 修改插件加载机智

This commit is contained in:
suxiaoxin 2017-09-28 20:26:54 +08:00
parent 1f6e5b31e3
commit ad34fcb514
6 changed files with 18 additions and 18 deletions

View File

@ -246,7 +246,6 @@ export default class GroupList extends Component {
}
render() {
console.log(this.props);
const { currGroup } = this.props;
const delmark = <Menu.Item>
<span onClick={() => this.showModal(TYPE_EDIT)}>编辑分组</span>

1
client/plugin-module.js Normal file
View File

@ -0,0 +1 @@
module.exports = {qsso : require('plugins/yapi-plugin-qsso/client.js')}

View File

@ -80,20 +80,17 @@ pluginModule = {
emitHook: emitHook
}
config.plugins.forEach(plugin => {
let pluginModuleList = require('./plugin-module.js');
config.plugins.forEach(plugin=>{
if (!plugin) return null;
if (!plugin.enable) return null;
if (plugin.client) {
let p = require(`plugins/yapi-plugin-${plugin.name}/client.js`);
p.call(pluginModule, plugin);
if(plugin.client){
pluginModuleList[plugin.name].call(pluginModule, plugin)
}
})
systemPlugins.forEach(plugin => {
if (!plugin) return null;
if (!plugin.enable) return null;
if (plugin.client) {
let p = require(`exts/yapi-plugin-${plugin.name}/client.js`);
p.call(pluginModule, plugin);

View File

@ -1,3 +0,0 @@
module.exports = function(){
return null;
};

View File

@ -1,5 +1,5 @@
const yapi = require('./yapi.js');
const plugin_path = yapi.path.join(yapi.WEBROOT, 'plugins');
const plugin_path = yapi.path.join(yapi.WEBROOT, 'node_modules');
const plugin_system_path = yapi.path.join(yapi.WEBROOT, 'exts');
const initPlugins = require('../common/lib.js').initPlugins;
var extConfig = require('../common/config.js').exts;

16
ykit.js
View File

@ -26,10 +26,16 @@ function fileExist (filePath){
};
function initPlugins(){
var scripts = [] ;
if(config.plugins && Array.isArray(config.plugins)){
config.plugins = config.plugins.filter(item=>{
return fileExist(path.resolve(__dirname, 'plugins/yapi-plugin-' + item + '/client.js'))
return fileExist(path.resolve(__dirname, 'node_modules/yapi-plugin-' + item + '/client.js'))
})
config.plugins.forEach((plugin)=>{
scripts.push(`${plugin} : require('plugins/yapi-plugin-${plugin}/client.js')`)
})
scripts = "module.exports = {" + scripts.join(",") + "}";
fs.writeFileSync('client/plugin-module.js', scripts);
}
}
@ -50,13 +56,13 @@ module.exports = {
defaultQuery.plugins.push(["import", { libraryName: "antd"}])
return defaultQuery;
},
exclude: /node_modules/
}
exclude: /node_modules\/(?!yapi-plugin)/
}
}],
// devtool: 'cheap-source-map',
config: function (ykit) {
return {
exports: [
exports: [
'./index.js'
],
commonsChunk: {
@ -110,7 +116,7 @@ module.exports = {
baseConfig.context = path.resolve(__dirname, './client');
baseConfig.resolve.alias.client = '/client';
baseConfig.resolve.alias.common = '/common';
baseConfig.resolve.alias.plugins = '/plugins';
baseConfig.resolve.alias.plugins = '/node_modules';
baseConfig.resolve.alias.exts = '/exts';
baseConfig.output.prd.path = 'static/prd';
baseConfig.output.prd.publicPath = '';