In this article we focus purely on scaffolding: generating the initial VS Code extension project using the Yeoman generator, with TypeScript and esbuild, ready for you to start coding.
Prerequisites
Before you scaffold the project, ensure you have:
- Node.js 18+ installed (check with
node -v). - Git installed (check with
git --version).
These are required because the generator uses Node, and the template can optionally initialise a Git repository for you.
Generating the extension with Yeoman
VS Code’s official generator is distributed as a Yeoman generator. You don’t need to install anything globally; you can invoke it directly via npx:
# One-time scaffold (no global install needed)
npx --package yo --package generator-code -- yo code
This command:
- Downloads
yo(Yeoman) andgenerator-codeon demand. - Runs the VS Code extension generator.
- Prompts you with a series of questions about the extension you want to create.
Recommended answers to the generator prompts
When the interactive prompts appear, choose:
? What type of extension do you want to create? → New Extension (TypeScript)
? What's the name of your extension? → my-ai-extension
? What's the identifier? → my-ai-extension
? Initialize a git repository? → Yes
? Which bundler to use? → esbuild
? Which package manager? → npm
Why these choices matter:
- New Extension (TypeScript) – gives you a typed development experience and a standard project layout.
- Name / Identifier – the identifier becomes the technical ID used in the marketplace and in settings; pick something stable and lowercase.
- Initialize a git repository – sets up Git so you can immediately start version-controlling your work.
- esbuild – a modern, fast bundler that creates a single bundled
extension.jsfor VS Code. - npm – a widely used default package manager; you can adapt to pnpm/yarn later if needed.
After you answer the prompts, Yeoman will generate the project in a new folder named after your extension (e.g. my-ai-extension).
Understanding the generated structure
Open the new folder in VS Code. The generator gives you a standard layout, including:
src/extension.ts
This is the entry point of your extension. It exportsactivateand (optionally)deactivate. All your activation logic, command registration, and other behaviour start here.package.json
This acts as the extension manifest. It contains:- Metadata (name, version, publisher).
"main"field pointing to the compiled bundle (e.g../dist/extension.js)."activationEvents"describing when your extension loads."contributes"describing commands, configuration, views, etc., that your extension adds to VS Code.
From an architectural perspective, package.json is the single most important file: it tells VS Code what your extension is and how and when it integrates into the editor.
You’ll also see other generated files such as:
tsconfig.json– TypeScript compiler configuration.- Build scripts in
package.json– used to compile and bundle the extension with esbuild. .vscode/launch.json– debug configuration for running the extension in a development host.
At this stage, you don’t need to modify any of these to get a working scaffold.
Running the scaffolded extension
Once the generator finishes:
-
Install dependencies:
cd my-ai-extension npm install -
Open the folder in VS Code (if you aren’t already).
-
Press F5.
VS Code will:
- Run the build task defined by the generator.
- Launch a new Extension Development Host window.
- Load your extension into that window.
In the Extension Development Host:
- Open the Command Palette.
- Run the sample command that the generator added (typically named something like “Hello World”).
If the command runs and shows the sample notification, you have a fully working scaffolded extension. From here, you can start replacing the generated sample logic in src/extension.ts and adjusting package.json to declare your own contributions.
Leave a Reply