网站首页 > 技术文章 正文
首先,请记住:
它在新版本的脚手架项目里面非常重要
它有什么用呢?
inspect internal webpack config
能快速地在控制台看到对应生成的 webpack 配置对象。
首先它是 vue 的一个扩展命令,在文件 @vue/cli/bin/vue.js 中定义了 command
还是依赖了工具包 commander
const program = require('commander')
代码配置如下:
program .command('inspect [paths...]')
.description('inspect the webpack config in a project with vue-cli-service')
.option('--mode <mode>')
.option('--rule <ruleName>', 'inspect a specific module rule')
.option('--plugin <pluginName>', 'inspect a specific plugin')
.option('--rules', 'list all module rule names')
.option('--plugins', 'list all plugin names')
.option('-v --verbose', 'Show full function definitions in output')
.action((paths, cmd) => {
require('../lib/inspect')(paths, cleanArgs(cmd)
)})
这里的 option 比较多:
mode
rule
plugin
rules
plugins
verbose
在前面的文章中,我们比较常用的有 rule 相关的
再接着看一下 lib/inspect.js
文件:接受 2 个参数:
paths
args
module.exports = function inspect (paths, args) {}
核心还是找到 @vue/cli-service
,先获取当前执行命令的目录:
const cwd = process.cwd()
let servicePath = resolve.sync('@vue/cli-service', { basedir: cwd }
)
最终执行了 node ***/node_modules/@vue/cli-service/bin/vue-cli-service.js inspect
再带上参数:
调用了工具包 execa
:
const execa = require('execa')
execa('node', [ binPath, 'inspect', ...(args.mode ? ['--mode', args.mode] : []), ...(args.rule ? ['--rule', args.rule] : []), ...(args.plugin ? ['--plugin', args.plugin] : []), ...(args.rules ? ['--rules'] : []), ...(args.plugins ? ['--plugins'] : []), ...(args.verbose ? ['--verbose'] : []), ...paths], { cwd, stdio: 'inherit' })
那我们接着往下看,后面就是去 cli-service 目录了:
@vue/cli-service/lib/commands/inspect.js
通过 api.registerCommand 来注册一个:
module.exports = (api, options) => { api.registerCommand('inspect', { }, args => { })}
在回调函数里面会处理之前的 option 传递的参数:
1、处理 rule
if (args.rule) {
res = config.module.rules.find(
r => r.__ruleNames[0] === args.rule
)}
2、处理 plugin
if (args.plugin) { res = config.plugins.find(
p => p.__pluginName === args.plugin
)}
3、处理 rules
if (args.rules) { res = config.module.rules.map(r => r.__ruleNames[0])}
4、处理 plugins
if (args.plugins) { res = config.plugins.map(
p => p.__pluginName || p.constructor.name
)}
其他分支情况比较少用,暂时不做展开。
最后多是通过 webpack-chain
的 toString
函数来生成,最终在控制台打印:
You can inspect the generated webpack config using config.toString()
. This will generate a stringified version of the config with comment hints for named rules, uses and plugins.
注意:这个参数还有 verbose
const { toString } = require('webpack-chain')
const output = toString(res, { verbose })
猜你喜欢
- 2024-09-27 一文带你彻底搞懂 NPM 知识点「进阶篇」
- 2024-09-27 深入探索Vue3:将您的项目打包为生产版本
- 2024-09-27 「Vue3教程」创建你的第一个Vue 3项目
- 2024-09-27 Vue3亮点:打造和发布你自己的组件库,简单步骤助你成为前端大神
- 2024-09-27 mac电脑如何安装VUE环境及预览(mac怎么安装vue)
- 2024-09-27 vue实战——自定义基础路径,端口号
- 2024-09-27 为了实践微前端,重构了自己的导航网站
- 2024-09-27 重磅!Vue CLI 3.0正式发布,带来多项重大更新
- 2024-09-27 运行 npm run xxx 的时候发生了什么?
- 2024-09-27 Vue全家桶-使用总结(国家基本药物使用情况分析总结)
- 1515℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 577℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 514℃MySQL service启动脚本浅析(r12笔记第59天)
- 487℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 486℃启用MySQL查询缓存(mysql8.0查询缓存)
- 470℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 450℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 448℃MySQL server PID file could not be found!失败
- 最近发表
-
- 宝塔面板Nginx如何提高网站访问速度?
- 接口调试工具ApiPost中form-data/x-www-form-urlencoded/raw区别
- 高并发场景下,Nginx性能如何提升10倍?
- 高并发场景下,Nginx如何抗住千万级流量?
- 浏览器中在线预览pdf文件,pdf.mjs插件实现web预览pdf
- 为什么你的网站加载慢?90%的人忽略了这2个设置。
- 别再无脑复制Nginx配置了!掌握这10个"性能核弹"级参数
- 你的Nginx配置,可能就是你网站最慢的一环,注意这几个优化参数
- 深入浅出HTTP压缩技术(http2压缩)
- C程序设计之:1-1/2+1/3-... + 1/n 的和
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (83)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- c语言min函数头文件 (68)
- asynccallback (71)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)