mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-05-05 11:30:06 -05:00
d595adacf4
BREAKING CHANGE: PluginAPI.setMode() has been removed. Instead, for a plugin to
sepcify the default mode for a registered command, the plugins should expose
`module.exports.defaultModes` in the form of `{ [commandName]: mode }`.
close #959
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
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 => {
|
|
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))
|
|
})
|
|
}
|
|
|
|
module.exports.defaultModes = {
|
|
inspect: 'development'
|
|
}
|