Skip to content

Commit 82349ba

Browse files
committed
feat(inspect): add --rule and --plugin options for inspect command
1 parent 853662c commit 82349ba

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/@vue/cli-service/lib/commands/inspect.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ module.exports = (api, options) => {
8383
usage: 'vue-cli-service inspect [options] [...paths]',
8484
options: {
8585
'--mode': 'specify env mode (default: development)',
86+
'--rule': 'inspect a specific module rule',
87+
'--plugin': 'inspect a specific plugin',
8688
'--verbose': 'show full function definitions in output'
8789
}
8890
}, args => {
@@ -94,7 +96,11 @@ module.exports = (api, options) => {
9496
const paths = args._
9597

9698
let res
97-
if (paths.length > 1) {
99+
if (args.rule) {
100+
res = config.module.rules.find(r => r.__ruleName === args.rule)
101+
} else if (args.plugin) {
102+
res = config.plugins.find(p => p.__pluginName === args.plugin)
103+
} else if (paths.length > 1) {
98104
res = {}
99105
paths.forEach(path => {
100106
res[path] = get(config, path)
@@ -106,7 +112,7 @@ module.exports = (api, options) => {
106112
}
107113

108114
const pluginRE = /(?:function|class) (\w+Plugin)/
109-
console.log(stringify(res, (value, indent, stringify) => {
115+
const output = stringify(res, (value, indent, stringify) => {
110116
// shorten long functions
111117
if (
112118
!args.verbose &&
@@ -151,7 +157,9 @@ module.exports = (api, options) => {
151157
}
152158

153159
return stringify(value)
154-
}, 2))
160+
}, 2)
161+
162+
console.log(output)
155163
})
156164
}
157165

packages/@vue/cli/bin/vue.js

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ program
6868
program
6969
.command('inspect [paths...]')
7070
.option('--mode <mode>')
71+
.option('--rule <ruleName>', 'inspect a specific module rule')
72+
.option('--plugin <pluginName>', 'inspect a specific plugin')
7173
.option('-v --verbose', 'Show full function definitions in output')
7274
.description('inspect the webpack config in a project with vue-cli-service')
7375
.action((paths, cmd) => {

packages/@vue/cli/lib/inspect.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module.exports = function inspect (paths, args) {
1919
binPath,
2020
'inspect',
2121
...(args.mode ? ['--mode', args.mode] : []),
22+
...(args.rule ? ['--rule', args.rule] : []),
23+
...(args.plugin ? ['--plugin', args.plugin] : []),
2224
...(args.verbose ? ['--verbose'] : []),
2325
...paths
2426
], { cwd, stdio: 'inherit' })

0 commit comments

Comments
 (0)