前言全局说明
vsCode插件包 package.json 字段说明
一、说明
1.1 调试环境:
Windows 11 家庭版 24H2 26100.4061
vscode 1.85.2 绿色版
二、官方说明:
https://code.visualstudio.com/api/references/extension-manifest
三、文件 package.json 字段说明
{
"name": "jd-gold-price-monitor", // 模块包名,必须全小写,无空格(可用连字符)
"displayName": "JD Gold Price Monitor", // 显示在扩展列表的名称
"description": "Monitor gold price from JD", // 模块包描述
"version": "0.0.8", // 模块包版本
"author": "iMaeGoo", // 模块包作者
"publisher": "iMaeGoo", // 模块包
"icon": "gold.png", // 显示在扩展列表的图标
"repository": { // 更新来源
"type": "git", // git
"url": "https://github.com/imaegoo/jd-gold-price-monitor.git"
},
"engines": {
"vscode": "^1.85.0" // 最低兼容的 VS Code 版本为1.85.0
},
"categories": [
"Other"
],
"activationEvents": [ // 定义何时加载插件(如 onStartup)
"onStartup",
"onStartupFinished"
],
"main": "./extension.js", // 入口文件路径
"contributes": {
"commands": [ // 声明插件提供的命令(可选)
{
"command": "gold-price-monitor.start",
"title": "Start Gold Price Monitor"
}
]
},
"__metadata": { // vscode安装生成的插件相关信息
"id": "1119322d-9ca0-4863-ab90-6092a3a9c64a",
"publisherId": "09157984-620a-4ff5-910d-e6f0ceaec1a4",
"publisherDisplayName": "iMaeGoo",
"targetPlatform": "undefined",
"isApplicationScoped": false,
"updated": true,
"isPreReleaseVersion": false,
"installedTimestamp": 1772977972435,
"pinned": false,
"preRelease": false
}
}
四、功能分类整理
4.1. 基础信息字段
| 字段名 |
类型 |
必填 |
作用 |
示例 |
| name |
string |
✅ |
插件唯一标识(全小写,无空格,可用连字符) |
"gold-price-monitor" |
| displayName |
string |
✅ |
在扩展市场中显示的名称 |
"Gold Price Monitor" |
| description |
string |
✅ |
插件的简短描述 |
"显示实时黄金价格到状态栏" |
| version |
string |
✅ |
语义化版本号(major.minor.patch) |
"0.0.1" |
| publisher |
string |
✅ |
发布者 ID(与 VS Code 市场账号关联) |
"your-name" |
| icon |
string |
❌ |
插件图标路径(相对路径,支持 PNG/SVG) |
"./images/icon.png" |
4.2 运行环境配置
| 字段名 |
类型 |
作用 |
示例 |
| engines |
object |
✅ 指定兼容的 VS Code 版本 |
"vscode": "^1.85.0" |
| main |
string |
✅ 插件入口文件路径(通常为 JS/TS) |
"./src/extension.js" |
| browser |
string |
❌ Web 版 VS Code 的入口文件 |
"./dist/web/extension.js" |
4.3 激活事件(Activation Events)
| 字段名 |
类型 |
作用 |
常见值 |
| activationEvents |
string[] |
✅ 定义何时激活插件 |
["onStartup"], ["onCommand:xxx"], ["onLanguage:python"] |
4.4 功能贡献点(Contributes)
| 字段名 |
类型 |
作用 |
子字段示例 |
| contributes.commands |
array |
注册插件提供的命令 |
"command": "gold.refresh", "title": "Refresh Price" |
| contributes.menus |
object |
添加右键菜单项 |
"editor/context": [{ "command": "gold.refresh" }] |
| contributes.configuration |
object |
定义插件的可配置选项 |
"properties": { "gold.apiUrl": { "type": "string" } } |
| contributes.views |
object |
在侧边栏添加自定义视图 |
"explorer": [{ "id": "goldView", "name": "Gold Prices" }] |
4.5 依赖管理
| 字段名 |
类型 |
作用 |
示例 |
| dependencies |
object |
❌ 生产环境依赖(如 axios) |
"axios": "^1.6.0" |
| devDependencies |
object |
❌ 开发依赖(如 @types/vscode) |
"@types/vscode": "^1.85.0" |
4.6 扩展市场元数据
| 字段名 |
类型 |
作用 |
示例 |
| categories |
string[] |
❌ 插件分类(市场展示) |
["Programming", "Debuggers"] |
| keywords |
string[] |
❌ 搜索关键词 |
["gold", "price", "finance"] |
| repository |
object |
❌ 代码仓库链接 |
"url": "https://github.com/your-repo" |
| license |
string |
❌ 开源许可证 |
"MIT" |
4.7 调试与测试
| 字段名 |
类型 |
作用 |
示例 |
| scripts |
object |
❌ 定义 npm 脚本 |
"compile": "tsc -p ./" |
| extensionDependencies |
string[] |
❌ 依赖的其他插件 |
["ms-python.python"] |
免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。
参考、来源:
https://www.wenxiaobai.com/3e0c5dd9-e0af-4ac4-afcb-fe709e158da1