Electron Development Guide: Environment Setup, Project Creation, and Source Code Structure
This article provides a comprehensive guide to Electron development, covering its cross‑platform architecture, environment preparation, installation commands, project initialization with both the quick‑start template and vue‑cli, and detailed explanations of the source and application directory structures.
Electron is a cross‑platform development framework built on Chromium and Node.js that enables developers to create desktop applications for macOS, Windows, and Linux using HTML, CSS, and JavaScript; popular apps such as VS Code and Atom are built with it.
Environment setup : Install Node.js (download from the official site or use Homebrew) and optionally switch the npm registry to the Taobao mirror:
npm config set registry http://registry.npm.taobao.org/npm install -g cnpm --registry=https://registry.npm.taobao.orgVerify the Vue‑CLI version and upgrade if necessary:
vue -Vnpm install @vue/cli -gInstall Electron globally (or via cnpm) and confirm the installation:
npm install -g electroncnpm install -g electronelectron --versionCreating and running a project : Clone the official quick‑start repository, install dependencies, and start the app:
git clone https://github.com/electron/electron-quick-startcd electron-quick-startnpm installnpm startAlternatively, use the vue‑cli electron‑vue template: vue init simulatedgreg/electron-vue After selecting the prompts, install the project dependencies and run the template:
npm installnpm run devElectron source tree : The top‑level directories include atom (the main source), chromium_src, docs, spec, and build configuration files. Developers mainly work in src, package.json, and appveyor.yml, with additional important folders such as script, tools, vendor, node_modules, out, dist, and external_binaries.
Application project structure : An Electron‑Vue project contains directories like electron-vue (template config), build (build scripts), config (basic settings), node_modules (dependencies), src (source code), static (static assets), index.html (single HTML entry), and package.json (dependency list).
Within src, the main folder holds index.js (application entry) and index.dev.js (development‑only setup). The renderer folder contains assets, components, router, store/modules, and the Vue entry main.js.
Process model : Electron applications consist of a single main process (running the main script) that creates BrowserWindow instances, each of which runs its own renderer process. The main process manages windows and IPC, while each renderer process runs a web page with full Node.js API access.
Related examples : Sample projects such as electron‑vue‑cloud‑music and electron‑vue‑music demonstrate real‑world usage.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
