# Migrate a VS Code Extension from Webpack to esbuild

Yes. An agent replaces your extension's webpack config with an esbuild script that writes the same dist/extension.js, keeps tsc and ESLint as checks, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/migrate-webpack-to-esbuild/vscode-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads what the current build produces before it swaps the bundler. In an extension shaped like `webpack-sample` in microsoft/vscode-extension-samples, `package.json` points `main` at `./dist/extension`, requires `vscode ^1.100.0`, and runs `webpack --mode production` for `vscode:prepublish`, `webpack --mode development` for `webpack`, the same with `--watch` for `webpack-dev`, and `tsc -p ./` for `test-compile`. `webpack.config.js` sets `target: 'node'`, entry `./src/extension.ts`, output `dist/extension.js` as `commonjs2`, `devtool: 'source-map'`, the `vscode` module as an external, and `ts-loader` with `module: es6` overriding `tsconfig.json`, which itself compiles `commonjs` to `ES2024` with `strict` on and `outDir: out`.

The source is two files: `src/extension.ts` registers the `extension.helloWebpack` command and `src/math.ts` exports `add` and `sub`. There are no tests, and `.vscodeignore` excludes `src/**`, `tsconfig.json` and `webpack.config.js` from the package. The same repository has `esbuild-sample`, which the agent reads as the target shape: an `esbuild.js` that builds `src/extension.ts` with `bundle: true`, `format: 'cjs'`, `platform: 'node'`, `external: ['vscode']`, `outfile: 'dist/extension.js'`, `minify` only in production and `sourcemap` only outside it, plus a small plugin that prints errors in the form the `$esbuild-watch` problem matcher reads.

The agent writes that `esbuild.js` into the extension, then rewrites the scripts: `vscode:prepublish` becomes `npm run package`, `package` runs type checks, lint and `node esbuild.js --production`, `compile` does the same without minifying, `watch` runs `tsc --noEmit --watch` and `node esbuild.js --watch` in parallel through `npm-run-all`, and `check-types` is `tsc --noEmit`. `webpack`, `webpack-cli` and `ts-loader` leave `devDependencies`; `esbuild` and `npm-run-all` join them. `.vscodeignore` swaps `webpack.config.js` for `esbuild.js`, `.vscode/launch.json` changes its `preLaunchTask` from `npm: webpack` to the new watch task, and `.vscode/tasks.json` gains the two background tasks with the `$tsc-watch` and `$esbuild-watch` problem matchers.

Then it proves the bundle is the same thing under a different builder: `npm run package` produces `dist/extension.js`, the agent greps it to confirm `vscode` is still a bare `require` and `math.ts` is inlined, runs `npm run check-types` and `npm run lint` against the untouched `eslint.config.mjs`, and packages a `.vsix` with `vsce package` to confirm `.vscodeignore` still yields a bundle-only package. It opens a pull request with the diff and the size of the output file before and after, read from the two builds it ran.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Migrate this VS Code extension from webpack to esbuild. Write an esbuild.js that bundles src/extension.ts to dist/extension.js as CommonJS for Node with vscode external, source maps in development and minification in production, and a watch mode. Replace the webpack scripts in package.json with compile, watch, package and check-types scripts that keep tsc --noEmit and eslint as separate checks, remove webpack, webpack-cli and ts-loader from devDependencies, and update .vscodeignore, .vscode/launch.json and .vscode/tasks.json to the new build. Build in both modes, confirm the bundle keeps vscode as an external require, run the type check and lint, package a .vsix, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch. The diff deletes `webpack.config.js`, adds `esbuild.js`, rewrites the `scripts` and `devDependencies` in `package.json` with the matching `package-lock.json`, and touches `.vscodeignore`, `.vscode/launch.json` and `.vscode/tasks.json`. `main` in `package.json` still points at `dist/extension`, so the manifest VS Code reads is unchanged. The description lists each old script beside its new name.

The run's record keeps both builds, the `grep` that shows `require("vscode")` in the bundle and `add(` inlined from `math.ts`, the `tsc --noEmit` and `eslint` runs, and the `vsce package` output with the files that went into the `.vsix`. Nothing is published to the Marketplace.

Before merging, a reviewer presses F5 with the new `launch.json` to confirm the watch task starts and the command still shows its message, and checks that any native module or dynamic `require` the real extension has is listed in `external`, since esbuild cannot bundle those.

## Run it on every extension in the repository

A repository with many extensions, such as a samples collection or a monorepo, is one run per extension directory. From your own server, start one `POST /o/{org}/sessions` per directory with the repository in `resources` and the directory named in `input`; each run opens its own pull request, so a reviewer can merge the simple ones first.

A webhook on the API key posts `run.completed` or `run.failed` for each when its turn finishes, with the `session_url` to read the pull request link and the build logs.

## Why run it on Rush?

A bundler swap is judged by its output, and the only way to know the new `dist/extension.js` is equivalent is to build both, read them and package the result. The sandbox has Node, `vsce` and a clean `node_modules`, so the run does exactly that and keeps the output, rather than a reviewer trusting that the config looks right.

The change touches scripts, dependencies, ignore files and editor tasks, which is tedious by hand and easy to leave half done. One run produces one pull request with all of it and the proof, and a run per extension does the same across a collection.

## Frequently asked questions

### Does the migration change what VS Code loads?

No. `main` still points at `dist/extension`, the bundle is still CommonJS for Node, and `vscode` is still an external the host provides. Only the tool that writes the file changes.

### What happens to type checking, since esbuild does not do it?

It becomes its own step. `check-types` runs `tsc --noEmit`, `package` runs it before bundling, and the watch task runs it beside esbuild, so a type error still fails the build and shows in the Problems panel through the `$tsc-watch` matcher.

### My extension has a web build too. Is that covered?

A browser target needs `platform: 'browser'`, a different output path under `dist/web`, and polyfills for Node globals the webpack config may have added. The agent writes a second build entry in `esbuild.js` when `package.json` has a `browser` field and says what it polyfilled.

### Will the watch task work without an extra extension?

The `$esbuild-watch` problem matcher comes from the esbuild Problem Matchers extension, which the sample's `tasks.json` relies on. The pull request adds it to `.vscode/extensions.json` as a recommendation so a teammate is prompted to install it.

## More VS Code Extension jobs

- [Review Every Pull Request on a VS Code Extension Repository](https://getrush.ai/run/review-pull-requests/vscode-extension/)
- [Upgrade a VS Code Extension to the Latest API](https://getrush.ai/run/upgrade-vscode-engine/vscode-extension/)
- [Write Integration Tests for a VS Code Extension](https://getrush.ai/run/write-extension-tests/vscode-extension/)

## More jobs like this: Hand off a long task

- [Migrate a Chrome Extension from Webpack to Vite](https://getrush.ai/run/migrate-webpack-to-vite/chrome-extension/)
- [Migrate a Webpack 5 Project to Vite](https://getrush.ai/run/migrate-webpack-to-vite/webpack/)
- [Migrate a Yarn 4 Project to pnpm, Lockfile and Patches Included](https://getrush.ai/run/migrate-yarn-to-pnpm/yarn/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
