簡體   English   中英

有沒有辦法從 NPM 腳本打開 Visual Studio 代碼內部 powershell window?

[英]Is there a way to open a Visual Studio Code internal powershell window from NPM Script?

我目前正在使用 npm 腳本進行一些工作,但無法在線找到我的問題的答案!

我想通過鍵入一個命令來運行 3 個 NPM 腳本。 這里的腳本:

"start-jsonserver:platform": "ng serve --configuration jsonserver"

"start:corePlugins": "ng serve corePlugins",

"start:jsonserver": "cd../json-server & npm run start",

"start:allJsonEnvironment": "npm run start-jsonserver:platform && npm run start:corePlugins && npm run start:jsonserver",

請注意,最后一個命令無法正常工作,因為它在第一個ng serve “完成”后停止。 我也只用一個&嘗試過相同的命令,但這具有相同的效果

我找到了一個打開 3 個獨立的解決方案 Powershell windows:

"start:allJsonEnvironment": "start powershell npm run start-jsonserver:platform && start powershell npm run start:corePlugins && start powershell npm run start:jsonserver"

問題是這會打開正常的“獨立”Powershell windows,老實說,這真的很難看,我習慣於看到 VS Code 內部Powershell windows(同時 3 個),因為如果出現問題很容易發現。 像那樣:

在此處輸入圖像描述

因此,如果有辦法從 npm 腳本中打開這些“內部”Powershell windows,我將非常感謝幫助。

(我知道有一種方法可以在一個內部 window 中運行所有三個腳本,但這不是我要找的!)

好的,經過一些研究,我找到了另一種解決方案。

它不涉及 NPM 個腳本,但它實際上是更好的解決方案。

我對這個問題的個人解決方案是使用 VS Code Tasks 和dependsOn來連接所有三個命令:

{
    "version": "2.0.0",
    "tasks": 
        [
        {
            "label": "corePlugins",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/frontend"
            },
            "command": "ng serve corePlugins"
        },
        {
            "label": "serve_conf_json",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/frontend"
            },
            "command": "ng serve --configuration jsonserver"
        },
        {
            "label": "json-server",
            "group": "test",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/json-server"
            },
            "command": "npm run start"
        },
        {
            "label": "startAllJson",
            "dependsOn": [
                "json-server",
                "corePlugins",
                "serve_conf_json",
            ]
        }
    ]
}

所以現在我可以運行任務startAllJson ,它會打開 3 個 VSCode 終端並運行這些命令。

我知道這可能不是我問題的完美答案,但它是我在短時間內找到的最佳解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM