#DevHack: check how your VSCode extension is running
This post is over a year old, some of this information may be out of date.
When developing Visual Studio Code extensions, it might come in handy to know when running a production- or debug-build.
Typically in Node.js projects, we verify this by using the NODE_ENV
environment variable. Unfortunately, this approach cannot be used as VS Code runs in a different instance, and environment variables are lost.
Solution
Luckily, there is a way to check how your extension is running. You can check this via the vscode extension API.
You can retrieve the mode your extension is started with via the context.extensionMode
property.
import { ExtensionContext, ExtensionMode } from 'vscode';
export function activate(context: ExtensionContext) {
if (context.extensionMode === ExtensionMode.Development) { // Running in development mode } else if (context.extensionMode === ExtensionMode.Test) { // Running in test mode } else { // Running in production mode }}
There are three modes:
- Development
- Production
- Test
Hopefully, this #DevHack helps you to tweak your development flow when creating VS Code extensions.
Related articles
#DevHack: Open custom VSCode WebView panel and focus input
#DevHack: How to rename a file from a VSCode extension
In this DevHack we will learn how to rename a file from a vscode extension. If you are looking for a simple appraoch, this will be the one to use.
#DevHack: language-specific settings in a VSCode extension
Get to know how you can set language-specific settings straight from within the code of your Visual Studio Code extension.
Report issues or make changes on GitHub
Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.
Comments
Let's build together
Manage content in VS Code
Present from VS Code