Skip to content

Commit 57cabe7

Browse files
committed
:fix: 修复一些适配问题
1 parent ec485fa commit 57cabe7

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/commands/build/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Examples:
4343
}
4444
}
4545

46-
const mode = api.mode;
46+
const mode = args.mode || api.mode;
4747

4848
const webpack = tryRequire('webpack');
4949
if (!webpack) {

src/commands/inspect/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
'use strict';
2+
3+
const defaults = {
4+
target: 'app',
5+
};
6+
27
module.exports = function inspectCommand(api, opts) {
38

49
const chalk = require('chalk');
@@ -17,6 +22,7 @@ module.exports = function inspectCommand(api, opts) {
1722
'--rules': 'list all module rule names',
1823
'--plugins': 'list all plugin names',
1924
'--verbose': 'show full function definitions in output',
25+
'--target': `app | lib | plugin (default: ${defaults.target})`,
2026
},
2127
details: `
2228
Examples:
@@ -27,17 +33,30 @@ Examples:
2733
`.trim(),
2834
},
2935
args => {
36+
37+
// TODO 兼容, 下个版本删除
38+
if (args.t && !args.type) {
39+
args.type = args.t;
40+
logger.warn('you should be use "--type <type>"!!!');
41+
}
42+
43+
for (const key in defaults) {
44+
if (args[key] == null) {
45+
args[key] = defaults[key];
46+
}
47+
}
48+
3049
const { toString } = require('webpack-chain');
3150
const { highlight } = require('cli-highlight');
3251

33-
const { _: paths, verbose } = args;
34-
3552
const webpackConfig = api.resolveWebpackConfig({
3653
target: args.target,
3754
});
3855

3956
const config = _.cloneDeep(webpackConfig);
4057

58+
const { _: paths, verbose } = args;
59+
4160
let res;
4261
let hasUnnamedRule;
4362
if (args.rule) {

src/extends/enhance/index.js

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

1717
api.extendMethod('resolveChainableWebpackConfig', {
1818
description: 'resolve webpack-chain config.',
19-
}, ({ target = 'app' } = {}) => {
19+
}, options => {
2020
if (!initialized) {
2121
logger.throw('please call after "onInitWillDone" !');
2222
}
2323

2424
const webpackChainConfig = new Config();
2525
let finalWebpackChainConfig = webpackChainConfig;
26-
if (target === 'plugin') {
26+
if (options && options.target === 'plugin') {
2727
// TODO 针对所有 plugin 的配置进行处理
28-
finalWebpackChainConfig = api.applyPluginHooks('modifyChainWebpackPluginConfig', webpackChainConfig);
28+
finalWebpackChainConfig = api.applyPluginHooks('modifyChainWebpackPluginConfig', webpackChainConfig, options);
2929
api.applyPluginHooks('onChainWebpcakPluginConfig', finalWebpackChainConfig);
3030
} else {
3131
const selfConfig = api.selfConfig || {};
@@ -35,7 +35,7 @@ module.exports = function WebpackAdapter(api, opts) {
3535
delete _originalWebpackConfig.plugins; // 不接受 plugins
3636
webpackChainConfig.merge(_originalWebpackConfig);
3737

38-
finalWebpackChainConfig = api.applyPluginHooks('modifyChainWebpackConfig', webpackChainConfig);
38+
finalWebpackChainConfig = api.applyPluginHooks('modifyChainWebpackConfig', webpackChainConfig, options);
3939
api.applyPluginHooks('onChainWebpcakConfig', finalWebpackChainConfig);
4040
}
4141

@@ -45,13 +45,13 @@ module.exports = function WebpackAdapter(api, opts) {
4545

4646
api.extendMethod('resolveWebpackConfig', {
4747
description: 'resolve webpack config.',
48-
}, ({ target = 'app' } = {}) => {
49-
const finalWebpackChainConfig = api.resolveChainableWebpackConfig({ target });
48+
}, options => {
49+
const finalWebpackChainConfig = api.resolveChainableWebpackConfig(options);
5050
const webpackConfig = finalWebpackChainConfig.toConfig();
51-
if (target === 'plugin') {
52-
api.applyPluginHooks('modifyWebpackPluginConfig', webpackConfig);
51+
if (options && options.target === 'plugin') {
52+
api.applyPluginHooks('modifyWebpackPluginConfig', webpackConfig, options);
5353
} else {
54-
api.applyPluginHooks('modifyWebpackConfig', webpackConfig);
54+
api.applyPluginHooks('modifyWebpackConfig', webpackConfig, options);
5555
}
5656

5757
api.setState('webpackConfig', webpackConfig);

0 commit comments

Comments
 (0)