Tasks

Make a project start itself when it opens, using VS Code-style tasks.json, and run npm scripts from the menu.

Last updated 3 min read
On this page

Tasks let a project set itself up when it opens: install dependencies, start a dev server, open the preview. Codevre uses the same tasks.json format as VS Code, so existing projects work.

  1. .vscode/tasks.json
  2. .codevre/tasks.json (used when .vscode/tasks.json doesn't exist)

Both are JSONC (comments allowed). To create one, right-click the .codevre folder and choose Create tasks.json:

json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Start project",
      "type": "shell",
      "command": "vre run",
      "runOptions": { "runOn": "folderOpen" }
    }
  ]
}
FieldMeaning
labelThe task's name (taskName also works)
type"shell", or leave it out
commandA shell command line. npm install && npm run dev works
argsExtra arguments. Each is quoted and appended to command
options.cwdFolder to run in. Relative paths are relative to the project
options.envEnvironment variables, e.g. { "PORT": "4000" }
dependsOnA label or list of labels to run first
dependsOrder"sequence"
runOptions.runOn"folderOpen" runs the task when the project opens
presentation.reveal"always" opens the Terminal; "silent" (default) and "never" don't

Variables:

  • ${workspaceFolder} is the project folder in the runtime.
  • ${workspaceFolderBasename} is the project name.

Codevre ignores other fields, such as problemMatcher, group and isBackground.

A task runs automatically when it has "runOptions": { "runOn": "folderOpen" }, is a shell task, and has a command. This happens:

  • when a saved project finishes opening
  • when a template or uploaded workspace loads
  • after you clone a repository into the project root

Each independent startup task gets its own terminal tab. Run them again any time with Terminal ▸ Run Startup Tasks.

dependsOn chains are combined into one command (a && b && c). A cycle or a missing dependency stops the tasks with an error such as Task "dev" depends on missing task "install".

jsonc
{
  "version": "2.0.0",
  "tasks": [
    { "label": "install", "command": "npm install" },
    {
      "label": "dev",
      "command": "npm run dev",
      "dependsOn": "install",
      "runOptions": { "runOn": "folderOpen" },
      "presentation": { "reveal": "always" }
    }
  ]
}

A project from someone else could run anything on open, so Codevre asks first:

Allow automatic workspace tasks? .vscode/tasks.json wants to run when this project opens … Only allow this if you trust the project.

  • Allow and Run remembers your approval for that exact file and those commands, for your account in this browser. If the file changes, you're asked again.
  • Not Now skips them. You can review the file and run the tasks yourself.
  • Signed out, you're asked every time.
  • Startup tasks that only use cd <path> and vre run [file.html], joined by &&, run without asking. Anything with other commands, pipes, redirects, ;, $ or backquotes needs approval.
  • Terminal ▸ Run Startup Tasks is your own explicit action, so it doesn't ask.

Tasks run in Nodepod like anything else you type in the terminal. They never receive your GitHub token. See Tokens and secrets.

The Terminal menu has quick ways to run code without a tasks file:

CommandWhat it does
Run Active FileAn .html file opens in localhost:codevre; a .js, .mjs or .cjs file runs with node
Run Selected TextRuns the selection, or the current line, in the terminal
Run npm Script ▸One item per script in package.json (npm run <name>), plus npm install
Run Preview (VRE)Starts or reruns localhost:codevre
Run Startup TasksRuns the folderOpen tasks now

A build step plus the preview. Make npm start build, then open VRE:

json
// package.json
{ "scripts": { "build": "node build.js", "start": "npm run build && vre run index.html" } }
jsonc
// .codevre/tasks.json
{ "version": "2.0.0", "tasks": [
  { "label": "start", "command": "npm install && npm start", "runOptions": { "runOn": "folderOpen" } }
] }

Also set "vre.preview.autoRun": false in .codevre/settings.json, so the preview doesn't rerun on every source save before the build finishes. Your build calls vre run (or vre reload) when output is ready.

Docs