vscode插件的环境变量应该如何设置?

rxl*_*uli 7 typescript visual-studio-code

我尝试用cross-env设置,但用VSCode运行后未定义。我该如何修复它?

在此输入图像描述

yee*_*erk 5

您可以通过启动配置将环境变量传递给本地运行的 VS Code 扩展:

./.vscode/launch.json

// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run Extension",
            "type": "extensionHost",
            "request": "launch",
            "runtimeExecutable": "${execPath}",
            "args": [
                "--extensionDevelopmentPath=${workspaceFolder}"
            ],
            "outFiles": [
                "${workspaceFolder}/dist/extension.js"
            ],
            "preLaunchTask": "${defaultBuildTask}",
            "env": {
                "DEBUG": "true" // <---- EXAMPLE ENVIRONMENT VARIABLE
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)