angular-electron-boilerplate

October 29, 2024 ยท View on GitHub

This template provides a starting point of a modern and secure Electron app.

Screenshots

Screenshots

Project gloals

Use Angular for the Electron renderer process. Using a modern frontend framework helps you organize your codebase once your Electron app grows in complexity. Use the Angular CLI to generate components, routes, services and pipes. To give a modern look-and-feel Angular Material is used. This can easily be removed if it is not needed.

Use TypeScript for strongly-typed JavaScript.

Use webpack to pack main and preload to produce small fast build output. Everything is packed, so no need to include the /node_modules folder, in order to remove unnessesary files and to produce small and fast builds.

Use most secure Electron security settings: contextIsolation and disabled nodeIntegration and disabled enableRemoteModule. preload uses the contextBridge.

CI

CI

Builds

Getting started

Try out this template:

$ git clone https://github.com/frederiksen/angular-electron-boilerplate
$ cd angular-electron-boilerplate
$ npm install
$ npm run build:dev:all
$ npm start

NPM scripts

Builds

This builds a project and places the output in the /dist folder.

CommandDescription
npm run build:dev:allDeveloper builds of all projects
npm run build:prod:allProduction builds of all projects
npm run build:dev:mainDeveloper build of the Electron main project
npm run build:prod:mainProduction build of the Electron main project
npm run build:dev:rendererDeveloper build of the Electron renderer project
npm run build:prod:rendererProduction build of the Electron renderer project
npm run build:dev:preloadDeveloper build of the Electron preload project
npm run build:prod:preloadProduction build of the Electron preload project

Watch

Start watching for source code changes, and builds after each source code change.

CommandDescription
npm run build:watch:allWatch all projects
npm run build:watch:mainWatch the Electron main project
npm run build:watch:rendererWatch the Electron renderer project
npm run build:watch:preloadWatch the Electron preload project

Tests

Test commands.

CommandDescription
npm run test:testExecutes all Angular unit-tests
npm run test:e2eExecutes Angular end-2-end tests
npm run test:lintAngular lint

Updates

Commands for updating NPM modules.

CommandDescription
npm run update:angularEasy update to latest stable Angular
npm run update:electronEasy update to latest stable Electron
npm run update:webpackEasy update to latest stable WebPack

Packaging

CommandDescription
npm run packagePackage current /dist folder into an app in the /release-builds folder
npm run releaseFirst build a production build, then package /dist folder into an app in the /release-builds folder

Debugging

Screenshots

Use Code to get a super debug environment.

This extension is needed: Debugger for Chrome

First be sure to have build everything:

$ npm run build:dev:all

Now set some breakpoints both in the main source code and in the renderer source code.

From Code press Ctrl+Shift+D and select Main + Renderer and press F5

Packaging into an app

This is where all the magic happens.

$ npm run release

Then your app will be put into the /release-builds folder. Can build an app for Windows, macOS and Linux.