Skip to content

Commit fe00e16

Browse files
committed
feat: 增加对外暴露的方法
1 parent b03111f commit fe00e16

File tree

5 files changed

+38
-31
lines changed

5 files changed

+38
-31
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
},
3939
"license": "MIT",
4040
"devDependencies": {
41-
"@micro-app/plugin-deploy": "^0.0.6",
41+
"@micro-app/plugin-deploy": "^0.0.7",
4242
"@types/jest": "^24.9.1",
4343
"eslint-config-2o3t": "^2.0.1",
4444
"jest": "^24.9.0",
4545
"webpack": "^4.42.1"
4646
},
4747
"dependencies": {
48-
"@micro-app/cli": "^0.3.10",
48+
"@micro-app/cli": "^0.3.11",
4949
"@micro-app/plugin-webpack": "^0.0.11"
5050
}
5151
}

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ module.exports = function(api, vueConfig) {
1313
[BUILT_IN]: true,
1414
apply(_api) {
1515
// 修改默认配置
16-
const newVueConfig = _api.applyPluginHooks('modifyVueConfig', vueConfig);
17-
Object.assign(vueConfig, newVueConfig || {});
16+
_api.onInitDone(() => {
17+
const newVueConfig = _api.applyPluginHooks('modifyVueConfig', vueConfig);
18+
Object.assign(vueConfig, newVueConfig || {});
19+
});
1820
},
1921
});
2022

@@ -24,3 +26,6 @@ module.exports = function(api, vueConfig) {
2426

2527
return chainConfig(api, vueConfig, config);
2628
};
29+
30+
// 外部服务提前注册方法
31+
module.exports.registerMethod = require('./utils/registerMethod');

src/utils/createService.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,5 @@ module.exports = function() {
1515
});
1616
}
1717

18-
const PLUGIN_CHANGE_VUE_CONFIG_ID = 'vue-cli-plugin:plugin-modifyVueConfig-register';
19-
if (!service.hasPlugin(PLUGIN_CHANGE_VUE_CONFIG_ID)) {
20-
service.registerPlugin({
21-
id: PLUGIN_CHANGE_VUE_CONFIG_ID,
22-
[BUILT_IN]: true,
23-
apply(_api) {
24-
_api.registerMethod('modifyVueConfig', {
25-
type: _api.API_TYPE.MODIFY,
26-
description: 'modify vue config.',
27-
});
28-
},
29-
});
30-
}
31-
3218
return service;
3319
};

src/utils/registerMethod.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const { assert } = require('@micro-app/shared-utils');
4+
const { CONSTANTS } = require('@micro-app/core');
5+
const KEY = 'modifyVueConfig';
6+
7+
// 注册全局, hacker, 外部调用
8+
module.exports = function registerMethod(s) {
9+
assert(s, 'service must be required!');
10+
if (!s.hasKey(KEY)) {
11+
s.registerMethod(KEY, {
12+
type: CONSTANTS.API_TYPE.MODIFY,
13+
description: 'modify vue config.',
14+
});
15+
}
16+
};

yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,29 +323,29 @@
323323
dependencies:
324324
sourcemap-codec "^1.4.4"
325325

326-
"@micro-app/cli@^0.3.10":
327-
version "0.3.10"
328-
resolved "https://registry.yarnpkg.com/@micro-app/cli/-/cli-0.3.10.tgz#2081d92f9e1f97d74729def5328ae67401b03493"
329-
integrity sha512-pTUzHEs+oa0zw1CSEiaT0qCIf2DszZh3MqsPmYgbAKaZYP5SAU3+L4lasUKYBlHH82LZqBM5AWDfRkIQQA6Nrg==
326+
"@micro-app/cli@^0.3.11":
327+
version "0.3.11"
328+
resolved "https://registry.yarnpkg.com/@micro-app/cli/-/cli-0.3.11.tgz#b570284d25950fd3bf3cec9922a19b75a547def7"
329+
integrity sha512-BOUBSBaSjNWbg6jd3SvjJ5W6mXQr9m4sZjGf33eLoh6GpVcf7XF2XGnwKyLVQwcVKj7oJ75aL/+9vrxkc/utNA==
330330
dependencies:
331-
"@micro-app/core" "^0.3.19"
331+
"@micro-app/core" "^0.3.20"
332332
"@zkochan/cmd-shim" "^4.3.0"
333333
read-cmd-shim "^2.0.0"
334334
update-notifier "^4.1.0"
335335

336-
"@micro-app/core@^0.3.19":
337-
version "0.3.19"
338-
resolved "https://registry.yarnpkg.com/@micro-app/core/-/core-0.3.19.tgz#4a2b67a9b110a9cb9454ee641c14a526076963be"
339-
integrity sha512-u6AUTtn2pGCCanRakEG2WdWfqThpR6OLekEfZiXGKnC/O3palCDCOXtBkkndiU5HxI/8/O1xhgF0sF+6xkuGDw==
336+
"@micro-app/core@^0.3.20":
337+
version "0.3.20"
338+
resolved "https://registry.yarnpkg.com/@micro-app/core/-/core-0.3.20.tgz#f0a2d809eb82c8836c4dccaffdfb46383ed5554b"
339+
integrity sha512-qpo/tENg6Qpb2kZSudq/9XHb/kPpcYUhlG/7wSgNr+f4uLfV9gF98Cqpz25lg5hya1q2yY6/y8/rPhLOaHqj0g==
340340
dependencies:
341341
"@micro-app/shared-utils" "^0.1.16"
342342
dotenv "^8.2.0"
343343
dotenv-expand "^5.1.0"
344344

345-
"@micro-app/plugin-deploy@^0.0.6":
346-
version "0.0.6"
347-
resolved "https://registry.yarnpkg.com/@micro-app/plugin-deploy/-/plugin-deploy-0.0.6.tgz#75a0b435a8f6b12252c7204642383511f66521b7"
348-
integrity sha512-zvCqaKRTxwFx9A+A2p/RxdBJSDhYClpOJyQPmlx16RQwhqpFNUVdbR17qa7uaWCPyC11OM1IWAPiz10UA+XHeQ==
345+
"@micro-app/plugin-deploy@^0.0.7":
346+
version "0.0.7"
347+
resolved "https://registry.yarnpkg.com/@micro-app/plugin-deploy/-/plugin-deploy-0.0.7.tgz#cc413f4a98b700db8e84a8a3137c6ee41ae71642"
348+
integrity sha512-LcVQ3k3RSdsVaVd0HiBZJIF7RAZUAMHESekNt38xW4ZOPs9caU1UUhxVLNFo9ea5nCxqzvF/Ueo5e8iCQKW+WQ==
349349
dependencies:
350350
"@release-it/conventional-changelog" "^1.1.0"
351351
release-it "^13.1.1"

0 commit comments

Comments
 (0)