Skip to content

Commit 15a5dac

Browse files
committed
:fix: 修复 config.target 锁死
1 parent 6331fd6 commit 15a5dac

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/extends/enhance/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function WebpackAdapter(api, opts) {
1313

1414
api.extendMethod('resolveWebpackChain', {
1515
description: 'resolve webpack-chain config.',
16-
}, (webpackChainConfig = new Config()) => {
16+
}, (webpackChainConfig = new Config(), isServer = false) => {
1717
if (!initialized) {
1818
logger.throw('please call after "onInitWillDone" !');
1919
}
@@ -29,8 +29,12 @@ module.exports = function WebpackAdapter(api, opts) {
2929
webpackChainConfig.merge(_originalWebpackConfig);
3030

3131
const target = api.target; // target, 默认 web
32-
if ([ 'app', 'lib', 'web' ].includes(target)) { // 其它类型外部自己设置
33-
webpackChainConfig.target('web');
32+
if (!webpackChainConfig.get('target')) {
33+
if (isServer) {
34+
webpackChainConfig.target('node');
35+
} else if ([ 'app', 'lib', 'web' ].includes(target)) { // 其它类型外部自己设置
36+
webpackChainConfig.target('web');
37+
}
3438
}
3539

3640
const finalWebpackChainConfig = api.applyPluginHooks('modifyWebpackChain', webpackChainConfig);
@@ -42,8 +46,8 @@ module.exports = function WebpackAdapter(api, opts) {
4246

4347
api.extendMethod('resolveWebpackConfig', {
4448
description: 'resolve webpack config.',
45-
}, webpackChainConfig => {
46-
const finalWebpackChainConfig = api.resolveWebpackChain(webpackChainConfig);
49+
}, (webpackChainConfig, isServer = false) => {
50+
const finalWebpackChainConfig = api.resolveWebpackChain(webpackChainConfig, isServer);
4751
const webpackConfig = finalWebpackChainConfig.toConfig();
4852
const finalWebpackConfig = api.applyPluginHooks('modifyWebpackConfig', webpackConfig);
4953
api.applyPluginHooks('onWebpcakConfig', finalWebpackConfig);

src/extends/submodule/configParser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ module.exports = function configParser(selfConfig = {}) {
5252
}
5353

5454
function namespace() {
55-
const key = hash(selfConfig.key);
56-
const _namespace = subModule.namespace || key;
55+
const _namespace = subModule.namespace || selfConfig.namespace || hash(selfConfig.key);
5756
return _namespace;
5857
}
5958

@@ -65,6 +64,7 @@ module.exports = function configParser(selfConfig = {}) {
6564
return `${prefix()}${namespace()}-${key}`;
6665
}
6766

67+
// 如果没有新的设置,默认会用主应用配置
6868
function outputDir() {
6969
const _outputDir = subModule.outputDir || false;
7070
return _outputDir;

src/extends/webpack/configParser.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
22

3-
const { _, tryRequire, path } = require('@micro-app/shared-utils');
3+
const { _, hash, tryRequire, path } = require('@micro-app/shared-utils');
44

55
const DEFAULT_KEY = 'main';
66

7-
module.exports = function configParser(obj, key, extraConfig = {}) {
8-
const selfConfig = obj[key] || {};
7+
module.exports = function configParser(selfConfig, extraConfig = {}) {
98
const originalConfig = selfConfig.originalConfig || {};
109
const webpackConfig = originalConfig.webpack || {};
1110

@@ -142,10 +141,16 @@ module.exports = function configParser(obj, key, extraConfig = {}) {
142141
return entry;
143142
}
144143

144+
function namespace() {
145+
const _namespace = selfConfig.namespace || hash(selfConfig.key);
146+
return _namespace;
147+
}
148+
145149
return {
146150
staticPaths,
147151
htmls,
148152
html,
149153
entry,
154+
namespace,
150155
};
151156
};

src/extends/webpack/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function extendWebpack(api, opts) {
1616
const microsConfig = api.microsConfig;
1717
Object.keys(microsConfig).forEach(key => {
1818
const item = microsConfig[key];
19-
const _configParser = configParser(microsConfig, key, microsExtraConfig[key]);
19+
const _configParser = configParser(item, microsExtraConfig[key]);
2020
Object.assign(item, {
2121
entry: _configParser.entry(),
2222
html: _configParser.html(),

0 commit comments

Comments
 (0)