Quick compile builds for Elixir in VSCode

Joel Kemp
Elixir Learnings
Published in
2 min readSep 12, 2020

When you’re making changes in VSCode and you want a quick check to make sure the project compiles, you can either reach for a terminal and type mix compile or set up a quick build in VSCode and trigger it via a keyboard shortcut. I’ll show you how to set up the latter.

  • Look for a .vscode folder in your project (or create one)
  • Look for a tasks.json file in your .vscode directory or create that file
  • Insert the following task configuration in that file:
{
"version": "2.0.0",
"tasks": [
{
"label": "mix: compile",
"type": "shell",
"command": "mix compile",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
  • Note: If you already have a task in there, then just append the object in the tasks array above to your existing tasks array.
  • Save the file. You shouldn’t need to restart VSCode for it to take effect, but try that if the next steps don’t work.
  • Trigger the command using Terminal -> Run Build Task, or the keyboard shortcut attached to that (mine is Shift + CMD + B, on Mac).
  • You should then see a terminal window pop up in your editor with text similar to the following (with “tictactoe” being whatever your app is named, of course):

Now, anytime you need a quick sanity check that your code still compiles and doesn’t have any big errors, trigger that build task using your keyboard shortcut. It should speed up your development cycle a touch.

--

--