Comprehensive Guide to Building Cross‑Platform Desktop Applications with Electron
This article provides a step‑by‑step tutorial on installing Node, Vue‑CLI, and Electron, creating and running Electron projects, explaining the source directory layout, main and renderer processes, and showcasing real‑world examples such as a cloud music player and a QQ music client.
Although B/S architecture dominates web development, C/S applications still have a large market because they can access local files and system resources beyond the browser sandbox. Electron, built on Chromium and Node.js, enables developers to create cross‑platform desktop apps using HTML, CSS, and JavaScript.
Environment Setup
Before creating an Electron app, install the required tools:
npm config set registry http://registry.npm.taobao.org/
# or
npm install -g cnpm --registry=https://registry.npm.taobao.orgCheck Vue‑CLI version:
vue -VIf Vue‑CLI is missing or outdated, install/upgrade it:
npm install @vue/cli -gInstall Electron globally:
npm install -g electron
# or
cnpm install -g electronVerify installation:
electron --versionCreate and Run a Project
Clone the official quick‑start template and start it:
git clone https://github.com/electron/electron-quick-start
cd electron-quick-start
npm install
npm startAlternatively, use the electron‑vue scaffolding:
vue init simulatedgreg/electron-vue
# follow the prompts to generate the projectInstall dependencies and run the app:
npm install
npm run dev # development mode
npm run build # package for distributionElectron Source Directory
The source tree follows Chromium’s multi‑process architecture. Key folders include atom/app (system entry), atom/browser (main process code), atom/renderer (renderer process code), and shared atom/common . The src directory contains main (e.g., index.js , index.dev.js ) and renderer (assets, components, router, store, etc.).
Process Model
The main process runs the script defined in package.json (usually background.js ) and creates BrowserWindow instances. Each window runs in its own renderer process, which can access Node.js APIs, allowing deeper OS interaction than a regular browser.
Real‑World Examples
1. Electron‑Vue Cloud Music – a cross‑platform desktop music player built with Electron, Vue, and Ant Design Vue. Features include drag‑play, desktop lyrics, mini mode, custom tray menu, audio visualisation, auto‑update, Nedb persistence, and more. Repository: https://github.com/xiaozhu188/electron-vue-cloud-music
2. QQ Music Player – another Electron‑Vue project mimicking the QQ Music UI. Build and run with:
git clone https://github.com/SmallRuralDog/electron-vue-music.git
cd electron-vue-music
npm install
# development mode
npm run dev
# package for distribution
npm run buildBoth examples include screenshots of the running applications.
Source article: http://segmentfault.com/a/119000002137693
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.