vscode 源码解析 - 编译
Prerequisites
- Git
- Node.js version
>=20.x
- Python (required for node-gyp; check the node-gyp readme for the currently upported Python versions)
- A C/C++ compiler tool chain for your platform:
- Visual Studio Installer (Windows 10/11 x64)
- "Workloads": Desktop Development with C++
- "Individual components":
- MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (Latest)
- C++ ATL for latest build tools with Spectre Mitigations
- C++ MFC for latest build tools with Spectre Mitigations
- open a command prompt and run
npm config edit
and add or modify themsvs_version
setting equal to your vs version. (e.g.msvs_version=2022
for visual studio 2022) - Warning: Make sure your profile path only contains ASCII letters, e.g. John, otherwise, it can lead to node-gyp usage problems (nodejs/node-gyp/issues#297)
- Visual Studio Installer (Windows 10/11 x64)
Build
Install and build all of the dependencies using npm:
cd vscode
npm install
Then you have two options:
If you want to build from inside VS Code, you can open the
vscode
folder and start the build task withCtrl+Shift+B
. The build task will stay running in the background even if you close VS Code. If you happen to close VS Code and open it again, just resume the build by pressing Ctrl+Shift+B (CMD+Shift+B) again. You can kill it by running theKill Build VS Code
task or pressingCtrl+D
in the task terminal.If you want to build from a terminal, run
npm run watch
. This will run both the core watch task and watch-extension tasks in a single terminal.
The incremental builder will do an initial full build and will display a message that includes the phrase "Finished compilation" once the initial build is complete. The builder will watch for file changes and compile those changes incrementally, giving you a fast, iterative coding experience.
If the build step fails, or if the built version fails to run (see next section), run git clean -xfd
in your vscode
folder, then re-run npm install
.
Run
Desktop(Windows)
Running on Electron with extensions run in NodeJS:
.\scripts\code.bat
.\scripts\code-cli.bat
👉 Tip! If you receive an error stating that the app is not a valid Electron app, it probably means you didn't run npm run watch
first.
VS Code for the Web
.\scripts\code-web.bat
Extensions and UI run in the browser.
👉Besides npm run watch
also run npm run watch-web
to build the web bits for the built-in extensions.
Code Server Web
UI in the browser, extensions run in code server (NodeJS):
.\scripts\code-server.bat --launch