在视觉工作室代码扩展中捆绑与调试

发布于 2025-02-12 02:09:32 字数 378 浏览 1 评论 0 原文

我已经为VS代码写了一个扩展程序,现在正在为其创建一个软件包。

然后,建议将文件捆绑在一起,我用 eSbuild 来完成文件。包装有效,但它使我遇到了困境。在 package.json 中,我可以编写

"main": "./out/main.js",

可以让VS代码使用捆绑的代码;这会导致一个可用的软件包,但我无法调试代码。

或者我可以编写

"main": "./out/extension.js",

将VS代码定向到原始代码的内容;然后我可以调试,但我不会生成可用的软件包。

当然,我必须误解一些东西,但是这是什么?

I have written an extension for VS Code and now am creating a package for it.

It is recommended then to bundle the files, which I do with esbuild. Packaging works, but it leaves me with a dilemma. In package.json, I can either write

"main": "./out/main.js",

which lets VS Code use the bundled code; this results in a usable package but I cannot debug the code.

Or I can write

"main": "./out/extension.js",

which directs VS Code to the original code; then I can debug but I do not generate a usable package.

Surely I must misunderstand something, but what is it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

回心转意 2025-02-19 02:09:32

/abound.json中设置VS代码启动配置。

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "my extension",
      "type": "extensionHost",
      "request": "launch",
      "runtimeExecutable": "${execPath}",
      "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
      "outFiles": ["${workspaceFolder}/out/main.js"],
      "preLaunchTask": "${defaultBuildTask}"
    }
  }

假设您的eSbuild命令包括 - sourcemap 以生成源地图,在.vscode .json,以便使用您的Esbuild Watch NPM脚本:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "npm",
      "script": "esbuild-watch",
      "isBackground": true,
      "presentation": {
        "reveal": "never",
        "group": "watchers"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

Assuming your esbuild command includes --sourcemap to generate source maps, set up your VS Code launch configuration in .vscode/launch.json to use esbuild output:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "my extension",
      "type": "extensionHost",
      "request": "launch",
      "runtimeExecutable": "${execPath}",
      "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
      "outFiles": ["${workspaceFolder}/out/main.js"],
      "preLaunchTask": "${defaultBuildTask}"
    }
  }

Then define your default build task in .vscode/tasks.json so that it uses your esbuild watch npm script:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "npm",
      "script": "esbuild-watch",
      "isBackground": true,
      "presentation": {
        "reveal": "never",
        "group": "watchers"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}
苦行僧 2025-02-19 02:09:32

更新 yo Code 并从中生成新扩展名。样本已经配置为捆绑文件,因此您无需自己做任何事情。

但是,如果您想将Esbuild用于捆绑,那么您可能是一个人。去年已经提到了重建,但以后再也没有进步,

Update yo code and generate a new extension from it. The sample has already been configured to bundle the files so you don't need to do anything yourself.

But if you want to use esbuild for bundling, then probably you are on your own. Moving to rebuild has been mentioned last year, but no progress ever after, https://github.com/microsoft/vscode/issues/115023#issuecomment-771692495

昇り龍 2025-02-19 02:09:32

如果您在powershell终端中“ npm运行esbuild”,它将运行“ esbuild”脚本(我将其复制到package.json中。 /bundling-extension“ rel =“ nofollow noreferrer”> https://code.visalstudio.com/api/working-with-with-with-extensions/bundling-extension-extension-extension-extension )可能的。 (即使它正在运行

main.js。 。

我还没有对此进行过彻底的测试(我失去了这些东西,但我认为这可能会有所帮助。

If you "npm run esbuild" in a powershell terminal, it runs the "esbuild" script (which I copied into package.json from https://code.visualstudio.com/api/working-with-extensions/bundling-extension ) that uses --sourcemap, and that seems to make debugging possible. (You can use breakpoints in extension.ts even though it's running main.js.)

Then, you can replace the "watch" script names in tasks.json with "esbuild-watch", and it will automatically run esbuild when you make changes.

I haven't tested this thoroughly (I'm about as lost as you are with this stuff) but I thought this might help anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文