|
1 | 1 | module.exports = (api, options) => {
|
2 |
| - api.registerCommand('inspect', { |
3 |
| - description: 'inspect internal webpack config', |
4 |
| - usage: 'vue-cli-service inspect [options] [...paths]', |
5 |
| - options: { |
6 |
| - '--mode': 'specify env mode (default: development)', |
7 |
| - '--rule <ruleName>': 'inspect a specific module rule', |
8 |
| - '--plugin <pluginName>': 'inspect a specific plugin', |
9 |
| - '--rules': 'list all module rule names', |
10 |
| - '--plugins': 'list all plugin names', |
11 |
| - '--verbose': 'show full function definitions in output' |
12 |
| - } |
13 |
| - }, args => { |
14 |
| - const { get } = require('@vue/cli-shared-utils') |
15 |
| - const { toString } = require('webpack-chain') |
16 |
| - const config = api.resolveWebpackConfig() |
17 |
| - const { _: paths, verbose } = args |
| 2 | + api.registerCommand( |
| 3 | + 'inspect', |
| 4 | + { |
| 5 | + description: 'inspect internal webpack config', |
| 6 | + usage: 'vue-cli-service inspect [options] [...paths]', |
| 7 | + options: { |
| 8 | + '--mode': 'specify env mode (default: development)', |
| 9 | + '--rule <ruleName>': 'inspect a specific module rule', |
| 10 | + '--plugin <pluginName>': 'inspect a specific plugin', |
| 11 | + '--rules': 'list all module rule names', |
| 12 | + '--plugins': 'list all plugin names', |
| 13 | + '--verbose': 'show full function definitions in output' |
| 14 | + } |
| 15 | + }, |
| 16 | + args => { |
| 17 | + const chalk = require('chalk') |
| 18 | + const { get } = require('@vue/cli-shared-utils') |
| 19 | + const { toString } = require('webpack-chain') |
| 20 | + const config = api.resolveWebpackConfig() |
| 21 | + const { _: paths, verbose } = args |
18 | 22 |
|
19 |
| - let res |
20 |
| - if (args.rule) { |
21 |
| - res = config.module.rules.find(r => r.__ruleNames[0] === args.rule) |
22 |
| - } else if (args.plugin) { |
23 |
| - res = config.plugins.find(p => p.__pluginName === args.plugin) |
24 |
| - } else if (args.rules) { |
25 |
| - res = config.module.rules.map(r => r.__ruleNames[0]) |
26 |
| - } else if (args.plugins) { |
27 |
| - res = config.plugins.map(p => p.__pluginName || p.constructor.name) |
28 |
| - } else if (paths.length > 1) { |
29 |
| - res = {} |
30 |
| - paths.forEach(path => { |
31 |
| - res[path] = get(config, path) |
32 |
| - }) |
33 |
| - } else if (paths.length === 1) { |
34 |
| - res = get(config, paths[0]) |
35 |
| - } else { |
36 |
| - res = config |
37 |
| - } |
| 23 | + let res |
| 24 | + let hasUnnamedRule |
| 25 | + if (args.rule) { |
| 26 | + res = config.module.rules.find(r => r.__ruleNames[0] === args.rule) |
| 27 | + } else if (args.plugin) { |
| 28 | + res = config.plugins.find(p => p.__pluginName === args.plugin) |
| 29 | + } else if (args.rules) { |
| 30 | + res = config.module.rules.map(r => { |
| 31 | + const name = r.__ruleNames ? r.__ruleNames[0] : 'Nameless Rule (*)' |
| 32 | + |
| 33 | + hasUnnamedRule = hasUnnamedRule || !r.__ruleNames |
38 | 34 |
|
39 |
| - const output = toString(res, { verbose }) |
40 |
| - console.log(output) |
41 |
| - }) |
| 35 | + return name |
| 36 | + }) |
| 37 | + } else if (args.plugins) { |
| 38 | + res = config.plugins.map(p => p.__pluginName || p.constructor.name) |
| 39 | + } else if (paths.length > 1) { |
| 40 | + res = {} |
| 41 | + paths.forEach(path => { |
| 42 | + res[path] = get(config, path) |
| 43 | + }) |
| 44 | + } else if (paths.length === 1) { |
| 45 | + res = get(config, paths[0]) |
| 46 | + } else { |
| 47 | + res = config |
| 48 | + } |
| 49 | + |
| 50 | + const output = toString(res, { verbose }) |
| 51 | + console.log(output) |
| 52 | + |
| 53 | + // Log explanation for Nameless Rules |
| 54 | + if (hasUnnamedRule) { |
| 55 | + console.log(`--- ${chalk.green('Footnotes')} ---`) |
| 56 | + console.log(`*: ${chalk.green( |
| 57 | + 'Nameless Rules' |
| 58 | + )} were added through the ${chalk.green( |
| 59 | + 'configureWebpack()' |
| 60 | + )} API (possibly by a plugin) instead of ${chalk.green( |
| 61 | + 'chainWebpack()' |
| 62 | + )} (recommended). |
| 63 | + You can run ${chalk.green( |
| 64 | + 'vue-cli-service inspect' |
| 65 | + )} without any arguments to inspect the full config and read these rules' config.`) |
| 66 | + } |
| 67 | + } |
| 68 | + ) |
42 | 69 | }
|
43 | 70 |
|
44 | 71 | module.exports.defaultModes = {
|
|
0 commit comments