QuantumHive
QuantumHive

Reputation: 5683

Visual Code Run Build Task npm

I'm using Visual Studio Code 1.13.0 on Windows 10.
I have the following build script in my package.json:

{
  //omitted other props
  "scripts": {
    "build": "webpack"
  }
}

I've installed webpack with npm install --global webpack, so it's installed globally.

The webpack.config.js is irrelevant for my question.

When I run npm run build in the terminal, everything works fine. But when I run the Visual Code Tasks: Run Build Task (ctrl+shift+b or ctrl+shift+p > Run Build Task), then I'm getting the following message in the output window:

'"npm run build"' is not recognized as an internal or external command, operable program or batch file.

Why? (using npm version: 3.10.10)

Upvotes: 0

Views: 5830

Answers (2)

David Clarke
David Clarke

Reputation: 13256

tasks.json can be used for running multiple different tasks. This is @oleg-m's answer updated for version 2 of tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type":"npm",
            "script": "build",
            "group": "build"
        }
    ]
}

Upvotes: 3

Oleg M
Oleg M

Reputation: 265

You should create tasks.json file and specify build task with npm task runner as described here ctrl+shift+p > Configure Task Runner. In your case task.json file should looks something like that

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "npm",
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "tasks": [
        {
            "isBuildCommand": true,
            "taskName": "build",
            "args": ["run", "build"]
        }
    ]
}

Upvotes: 5

Related Questions