forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspect.js
45 lines (42 loc) · 1.34 KB
/
inspect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module.exports = (api, options) => {
api.registerCommand('inspect', {
description: 'inspect internal webpack config',
usage: 'vue-cli-service inspect [options] [...paths]',
options: {
'--mode': 'specify env mode (default: development)',
'--verbose': 'show full function definitions in output'
}
}, args => {
api.setMode(args.mode || 'development')
const get = require('get-value')
const stringify = require('javascript-stringify')
const config = api.resolveWebpackConfig()
const paths = args._
let res
if (paths.length > 1) {
res = {}
paths.forEach(path => {
res[path] = get(config, path)
})
} else if (paths.length === 1) {
res = get(config, paths[0])
} else {
res = config
}
const pluginRE = /(?:function|class) (\w+Plugin)/
console.log(stringify(res, (value, indent, stringify) => {
if (!args.verbose) {
if (typeof value === 'function' && value.toString().length > 100) {
return `function () { /* omitted long function */ }`
}
if (value && typeof value.constructor === 'function') {
const match = value.constructor.toString().match(pluginRE)
if (match) {
return `/* ${match[1]} */ ` + stringify(value)
}
}
}
return stringify(value)
}, 2))
})
}