Skip to content

Commit 9cebc62

Browse files
committed
feat(config): 支持 module.exports 形式配置文件
1 parent 4d825b3 commit 9cebc62

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/models/Project.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,25 @@ var Project = function () {
115115

116116
// 获取项目配置中的插件
117117
var configMethod = _this2._requireUncached(sysPath.join(_this2.cwd, _this2.configFile));
118+
var ykitConfigStartWith = 'ykit-config-';
118119
if (Array.isArray(configMethod.plugins)) {
119120
_this2.plugins = configMethod.plugins;
120121
}
121122

122123
// 通配置文件名获取插件
123124
if (_this2.extendConfig && _this2.extendConfig !== 'config') {
124-
var pluginName = 'ykit-config-' + _this2.extendConfig;
125+
var pluginName = ykitConfigStartWith + _this2.extendConfig;
125126
if (_this2.plugins.indexOf(pluginName) === -1 && _this2.plugins.indexOf('@qnpm/' + pluginName) === -1) {
126127
_this2.plugins.push(pluginName);
127128
}
128129
}
129130

130131
// 通过插件扩展配置
131132
_this2.plugins.map(function (pluginName) {
133+
if (pluginName.indexOf(ykitConfigStartWith) === -1) {
134+
pluginName = ykitConfigStartWith + pluginName;
135+
}
136+
132137
var localSearchPath = sysPath.join(_this2.cwd, 'node_modules/', pluginName);
133138
var localSearchPathQnpm = sysPath.join(_this2.cwd, 'node_modules/', '@qnpm/' + pluginName);
134139
var pluginPath = '';
@@ -165,9 +170,7 @@ var Project = function () {
165170
_module2.config.call(userConfig, options, _this2.cwd);
166171
}
167172
} else {
168-
if (_this2.extendConfig) {
169-
warn('没有找到 ykit-config-' + _this2.extendConfig + ' 配置插件.');
170-
}
173+
warn('没有找到 ' + pluginName + ' 配置插件.');
171174
}
172175
}
173176
});
@@ -205,7 +208,7 @@ var Project = function () {
205208
this.config.setExports(exports);
206209
this.config.setCompiler(userConfigObj.modifyWebpackConfig);
207210
this.config.setSync(userConfigObj.sync);
208-
this.setCommands(userConfigObj.command);
211+
this.setCommands(configMethod.commands || userConfigObj.command); // 后者兼容以前形式
209212
};
210213

211214
// 如果传入的是一个简单数组

src/models/Project.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,25 @@ class Project {
102102

103103
// 获取项目配置中的插件
104104
const configMethod = this._requireUncached(sysPath.join(this.cwd, this.configFile));
105+
const ykitConfigStartWith = 'ykit-config-';
105106
if(Array.isArray(configMethod.plugins)) {
106107
this.plugins = configMethod.plugins;
107108
}
108109

109110
// 通配置文件名获取插件
110111
if (this.extendConfig && this.extendConfig !== 'config') {
111-
const pluginName = 'ykit-config-' + this.extendConfig;
112+
const pluginName = ykitConfigStartWith + this.extendConfig;
112113
if(this.plugins.indexOf(pluginName) === -1 && this.plugins.indexOf('@qnpm/' + pluginName) === -1) {
113114
this.plugins.push(pluginName);
114115
}
115116
}
116117

117118
// 通过插件扩展配置
118119
this.plugins.map((pluginName) => {
120+
if(pluginName.indexOf(ykitConfigStartWith) === -1) {
121+
pluginName = ykitConfigStartWith + pluginName;
122+
}
123+
119124
const localSearchPath = sysPath.join(this.cwd, 'node_modules/', pluginName);
120125
const localSearchPathQnpm = sysPath.join(
121126
this.cwd,
@@ -154,9 +159,7 @@ class Project {
154159
module.config.call(userConfig, options, this.cwd);
155160
}
156161
} else {
157-
if (this.extendConfig) {
158-
warn('没有找到 ykit-config-' + this.extendConfig + ' 配置插件.');
159-
}
162+
warn('没有找到 ' + pluginName + ' 配置插件.');
160163
}
161164
}
162165
});
@@ -211,7 +214,7 @@ class Project {
211214
this.config.setExports(exports);
212215
this.config.setCompiler(userConfigObj.modifyWebpackConfig);
213216
this.config.setSync(userConfigObj.sync);
214-
this.setCommands(userConfigObj.command);
217+
this.setCommands(configMethod.commands || userConfigObj.command); // 后者兼容以前形式
215218
}
216219
}
217220

0 commit comments

Comments
 (0)