VSCode中开发入门级插件

环境准备

  • node
  • git
  • npm

初始化项目

// 安装需要的包
npm install -g yo generator-code

// 运行
yo code

这个脚手架会生成一个可以立马开发的项目。运行生成器,填写信息:

yo code

# ? What type of extension do you want to create? New Extension (TypeScript)
# ? What's the name of your extension? HelloWorld
### Press <Enter> to choose default for all options below ###

# ? What's the identifier of your extension? helloworld
# ? What's the description of your extension? LEAVE BLANK
# ? Enable stricter TypeScript checking in 'tsconfig.json'? Yes
# ? Setup linting using 'tslint'? Yes
# ? Initialize a git repository? Yes
# ? Which package manager to use? npm

code ./helloworld

完成后进入 VS Code,按下F5,你会立即看到一个插件发开主机窗口,其中就运行着插件。
在命令面板(Ctrl+Shift+P)中输入Hello World命令。

重点关注的文件

在项目生成之后,目录结构如下所示,其中最重要的文件是package.json和extension.js,了解这两个文件基本上就可以入门开发一个vscode插件了。

package.json

该文件是vscode扩展的清单文件,里面有很多字段,官方对每个字段都进行了详细阐述,我们重点阐述以下初始化后期清单文件。

{
  "name": "demo", // 插件名
  "displayName": "插件", // 显示在应用市场的名字
  "description": "我的第一个插件测试", // 具体描述
  "version": "0.0.1", // 插件的版本号
  "engines": {
    "vscode": "^1.60.0" // 最低支持的vscode版本
  },
  "categories": [
    "Other" // 扩展类别
  ],
  // 激活事件组,在那些事件情况下被激活
  "activationEvents": [
    "onCommand:hellotbq.helloWorld"
  ],
  // 插件的主入口文件
  "main": "./extension.js",
  //  定义命令
  "contributes": {
    // 命令
    "commands": [
      {
        "command": &
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叨槿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值