Prerequisites
Before building Blink, ensure you have the following installed:Node.js
Version 18.x or higher required for native module support
npm
Comes with Node.js, used for dependency management
Git
For cloning the repository and version control
Build Tools
Platform-specific tools for compiling native modules
Platform-Specific Requirements
- Windows
- macOS
- Linux
- Visual Studio Build Tools: Install from visualstudio.microsoft.com
- Python 3.x: Required for node-gyp
- Windows SDK: Included with Visual Studio Build Tools
Quick Start
Install Dependencies
This will install all npm packages including native modules:
The installation includes
node-pty, a native module that requires compilation. This may take a few minutes.Development Workflow
Available Scripts
| Script | Description |
|---|---|
npm run dev | Start development server with HMR |
npm run build | Compile TypeScript, build renderer, and package for Windows/Linux |
npm run lint | Run ESLint for code quality checks |
npm run preview | Preview production build locally |
Development Mode Details
When you runnpm run dev, the following happens:
- Vite Dev Server starts on
http://localhost:5173(renderer process) - vite-plugin-electron compiles
electron/main.tsand watches for changes - Electron window launches and loads from the dev server
- Hot Module Replacement enables instant UI updates without restart
Build Process
TypeScript Compilation
The build starts with TypeScript compilation:.d.ts files. Configuration:
tsconfig.json (excerpt)
Vite Build
Vite bundles the renderer and main processes:Vite Configuration Details
Vite Configuration Details
Electron Builder
Final step packages the application withelectron-builder:
Packaging Configuration
electron-builder Setup
Configuration is defined inpackage.json:
package.json (build config)
The
node_modules directory is included because node-pty contains platform-specific native binaries that must be bundled.Build Outputs
- Windows
- Linux
- macOS
Targets: NSIS installer and portable executableNSIS Installer Features:
- Per-user or system-wide installation
- Desktop and Start Menu shortcuts
- Uninstaller registration
- Auto-update support
Platform-Specific Builds
Build for Single Platform
Build Specific Targets
Debugging
Main Process Debugging
Add--inspect flag to debug Electron’s main process:
package.json
- Open
chrome://inspect - Click “Configure” and add
localhost:9229 - Your Electron process will appear under “Remote Target”
Renderer Process Debugging
DevTools are enabled by default in development:Ctrl+Shift+I or Cmd+Option+I.
Production Debugging
Temporarily enable DevTools in production:Dependency Management
Production Dependencies
These are bundled with the application:package.json (excerpt)
node-pty is a native module that must be rebuilt for the target Electron version during installation.Development Dependencies
Used only during development and building:package.json (excerpt)
Auto-Update System
Configuration
Auto-updates are configured in the main process:Update Flow
IPC Handlers
Troubleshooting
node-pty Build Failures
node-pty Build Failures
Problem: Native module compilation fails during
npm installSolutions:- Ensure build tools are installed (see Prerequisites)
- Clear npm cache:
npm cache clean --force - Delete
node_modulesand reinstall:rm -rf node_modules && npm install - Check Node.js version:
node --version(must be 18.x+)
Electron Window Doesn't Open
Electron Window Doesn't Open
Problem:
npm run dev runs but no window appearsSolutions:- Check console for errors
- Verify Vite dev server is running:
http://localhost:5173 - Kill orphaned Electron processes:
pkill -f electron - Clear Electron cache:
rm -rf ~/.config/Electron/
Build Output Missing Assets
Build Output Missing Assets
Problem: Packaged app is missing images or fontsSolutions:
- Ensure assets are in
public/directory - Check
filesarray in electron-builder config - Verify
VITE_PUBLICpath resolution in main.ts:38-40
Module Not Found Errors
Module Not Found Errors
Problem:
Cannot find module 'monaco-editor' or similarSolutions:- Ensure dependency is in correct section (dependencies vs devDependencies)
- For renderer imports, check Vite externals config
- For main process imports, check electron-builder externals
- Reinstall:
npm install
Terminal Not Working in Packaged App
Terminal Not Working in Packaged App
Problem: Terminal blank or crashes in production buildSolutions:
- Verify
node-ptyis independencies(not devDependencies) - Ensure
node-ptyis marked as external in vite.config.ts:18 - Check that
node_modulesis included in electron-builder files - Rebuild node-pty for correct Electron version:
npm rebuild node-pty --runtime=electron --target=30.0.1
CI/CD Pipeline
GitHub Actions Example
.github/workflows/build.yml
Performance Optimization
Production Build Tips
- Tree Shaking: Vite automatically removes unused code
- Minification: Enable in
vite.config.ts: - Code Splitting: Dynamic imports for large components:
Bundle Size Analysis
vite.config.ts
npm run build to generate an interactive bundle visualization.
Next Steps
Architecture
Deep dive into Blink’s technical architecture
Components
Explore React component APIs