Convert Figma logo to code with AI

maximegris logoangular-electron

Ultra-fast bootstrapping with Angular and Electron :speedboat:

5,636
1,373
5,636
16

Top Related Projects

6,405

:electron: A complete tool for building and publishing Electron applications

Clone to try a simple Electron app

An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.

Easily Build Your Vue.js App For Desktop With Electron

A Foundation for Scalable Cross-Platform Apps

Boilerplate application for Electron runtime

Quick Overview

Angular-Electron is a boilerplate project that combines Angular and Electron, allowing developers to build cross-platform desktop applications using web technologies. It provides a solid foundation for creating modern, responsive desktop apps with the power of Angular's frontend framework and Electron's ability to package web apps for desktop environments.

Pros

  • Seamless integration of Angular and Electron, simplifying the development of desktop applications
  • Regular updates and maintenance, ensuring compatibility with the latest versions of Angular and Electron
  • Includes a comprehensive set of development tools and scripts for building, testing, and packaging
  • Supports hot reload during development, enhancing the developer experience

Cons

  • May have a steeper learning curve for developers not familiar with both Angular and Electron
  • The boilerplate structure might be overwhelming for simple projects
  • Potential performance overhead compared to native desktop applications
  • Limited customization options for Electron-specific features out of the box

Code Examples

  1. Main process (Electron) code:
import { app, BrowserWindow, screen } from 'electron';
import * as path from 'path';
import * as fs from 'fs';

let win: BrowserWindow | null = null;

function createWindow(): BrowserWindow {
  const electronScreen = screen;
  const size = electronScreen.getPrimaryDisplay().workAreaSize;

  // Create the browser window.
  win = new BrowserWindow({
    x: 0,
    y: 0,
    width: size.width,
    height: size.height,
    webPreferences: {
      nodeIntegration: true,
      allowRunningInsecureContent: (serve) ? true : false,
      contextIsolation: false,
    },
  });

  // Load the index.html when not in development
  if (serve) {
    win.loadURL('http://localhost:4200');
  } else {
    win.loadURL(url.format({
      pathname: path.join(__dirname, 'dist/index.html'),
      protocol: 'file:',
      slashes: true
    }));
  }

  return win;
}

// This method will be called when Electron has finished initialization
app.on('ready', () => {
  createWindow();
});
  1. Angular component example:
import { Component } from '@angular/core';
import { ElectronService } from './core/services';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  constructor(private electronService: ElectronService) {
    if (electronService.isElectron) {
      console.log('Running in Electron');
      console.log('Electron ipcRenderer', this.electronService.ipcRenderer);
      console.log('NodeJS childProcess', this.electronService.childProcess);
    } else {
      console.log('Running in browser');
    }
  }
}
  1. IPC communication example:
// In Angular service
import { Injectable } from '@angular/core';
import { IpcRenderer } from 'electron';

@Injectable({
  providedIn: 'root'
})
export class IpcService {
  private ipc: IpcRenderer | undefined;

  constructor() {
    if (window.require) {
      try {
        this.ipc = window.require('electron').ipcRenderer;
      } catch (e) {
        throw e;
      }
    } else {
      console.warn('Electron IPC was not loaded');
    }
  }

  public send(channel: string, ...args): void {
    if (!this.ipc) {
      return;
    }
    this.ipc.send(channel, ...args);
  }

  public on(channel: string, listener: Function): void {
    if (!this.ipc) {
      return;
    }
    this.ipc.on(channel, listener);
  }
}

Getting Started

  1. Clone the repository:
    git clone https://github.com/maximegris/angular-electron.git
    

Competitor Comparisons

6,405

:electron: A complete tool for building and publishing Electron applications

Pros of Electron Forge

  • More comprehensive toolset for Electron app development, including packaging and distribution
  • Better integration with native Electron APIs and features
  • Actively maintained by the Electron team, ensuring compatibility with the latest Electron versions

Cons of Electron Forge

  • Steeper learning curve for developers new to Electron
  • Less opinionated about frontend framework choice, which may require more setup for Angular projects

Code Comparison

Angular Electron:

import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import * as url from 'url';

let win: BrowserWindow = null;
const args = process.argv.slice(1),
  serve = args.some(val => val === '--serve');

Electron Forge:

const { app, BrowserWindow } = require('electron');
const path = require('path');

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  });

Both repositories provide boilerplate code for creating Electron applications, but Angular Electron is specifically tailored for Angular projects, while Electron Forge offers a more flexible approach that can be adapted to various frontend frameworks.

Clone to try a simple Electron app

Pros of electron-quick-start

  • Simpler and more lightweight, ideal for beginners or small projects
  • Focuses solely on Electron, making it easier to understand core concepts
  • Faster setup and quicker to get a basic app running

Cons of electron-quick-start

  • Lacks built-in Angular integration, requiring more setup for Angular projects
  • Doesn't include advanced features or optimizations out of the box
  • Limited scaffolding and project structure guidance

Code Comparison

electron-quick-start:

const { app, BrowserWindow } = require('electron')

function createWindow () {
  const win = new BrowserWindow({ width: 800, height: 600 })
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

angular-electron:

import { app, BrowserWindow, screen } from 'electron';
import * as path from 'path';
import * as fs from 'fs';

let win: BrowserWindow | null = null;
const args = process.argv.slice(1),
  serve = args.some(val => val === '--serve');

function createWindow(): BrowserWindow {
  const size = screen.getPrimaryDisplay().workAreaSize;

The electron-quick-start repository provides a minimal Electron setup, while angular-electron offers a more comprehensive boilerplate with Angular integration and additional features for larger-scale applications.

An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.

Pros of electron-vue

  • Uses Vue.js, which is known for its simplicity and ease of learning
  • Includes Vuex for state management out of the box
  • Offers a more opinionated structure, which can lead to faster development

Cons of electron-vue

  • Less active maintenance compared to angular-electron
  • Smaller community and ecosystem than Angular
  • May require more manual configuration for advanced features

Code Comparison

electron-vue:

import Vue from 'vue'
import App from './App.vue'

new Vue({
  render: h => h(App)
}).$mount('#app')

angular-electron:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));

Both repositories provide boilerplate code for creating Electron applications with popular front-end frameworks. angular-electron uses Angular, which has a steeper learning curve but offers more built-in features and a larger ecosystem. electron-vue, on the other hand, leverages Vue.js, which is known for its simplicity and flexibility.

angular-electron tends to have more frequent updates and a larger community, which can be beneficial for long-term support and troubleshooting. However, electron-vue's simpler structure may be preferable for smaller projects or developers who prefer Vue.js.

The code comparison shows the entry point for both projects, highlighting the different syntax and setup required for each framework. Angular's approach is more verbose but provides stronger typing and dependency injection out of the box.

Easily Build Your Vue.js App For Desktop With Electron

Pros of vue-cli-plugin-electron-builder

  • Seamless integration with Vue CLI, allowing easy setup and configuration
  • Supports both Electron Builder and Electron Packager out of the box
  • Provides hot reloading for both main and renderer processes

Cons of vue-cli-plugin-electron-builder

  • Limited to Vue.js projects, whereas angular-electron supports Angular
  • May require additional configuration for complex Electron setups
  • Less comprehensive documentation compared to angular-electron

Code Comparison

vue-cli-plugin-electron-builder:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      builderOptions: {
        // Configure electron-builder options here
      }
    }
  }
}

angular-electron:

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, AppRoutingModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

The code snippets demonstrate the configuration approach for each project. vue-cli-plugin-electron-builder uses a Vue CLI plugin configuration file, while angular-electron follows the standard Angular module structure.

Both projects aim to simplify Electron development with their respective frameworks. vue-cli-plugin-electron-builder excels in Vue.js integration and ease of use, while angular-electron provides a more comprehensive boilerplate for Angular-based Electron applications. The choice between them largely depends on the preferred framework and specific project requirements.

A Foundation for Scalable Cross-Platform Apps

Pros of electron-react-boilerplate

  • More active community with frequent updates and contributions
  • Comprehensive testing setup with Jest and React Testing Library
  • Includes hot reloading for faster development

Cons of electron-react-boilerplate

  • Larger bundle size due to additional features and dependencies
  • Steeper learning curve for developers new to React or Electron

Code Comparison

electron-react-boilerplate:

import { MemoryRouter as Router, Routes, Route } from 'react-router-dom';
import './App.css';

export default function App() {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Hello />} />
      </Routes>
    </Router>
  );
}

angular-electron:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'Angular Electron';
}

The code comparison shows the different approaches to routing and component structure between React and Angular in these Electron boilerplates. electron-react-boilerplate uses React Router for navigation, while angular-electron relies on Angular's built-in routing system (not shown in this snippet).

Both boilerplates provide a solid foundation for building Electron applications with their respective frameworks. The choice between them largely depends on your preference for React or Angular, as well as the specific requirements of your project.

Boilerplate application for Electron runtime

Pros of electron-boilerplate

  • Simpler setup and structure, making it easier for beginners to get started
  • More lightweight and flexible, allowing for easier customization
  • Uses vanilla JavaScript, which may be preferred by some developers

Cons of electron-boilerplate

  • Lacks built-in Angular integration, requiring more setup for Angular projects
  • Fewer out-of-the-box features compared to angular-electron
  • May require more manual configuration for complex applications

Code Comparison

electron-boilerplate:

import { app, BrowserWindow } from "electron";
import * as path from "path";

const createWindow = () => {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
  });
  win.loadFile("index.html");
};

angular-electron:

import { app, BrowserWindow, screen } from 'electron';
import * as path from 'path';
import * as fs from 'fs';

let win: BrowserWindow | null = null;
const args = process.argv.slice(1),
  serve = args.some(val => val === '--serve');

function createWindow(): BrowserWindow {
  const size = screen.getPrimaryDisplay().workAreaSize;

Both repositories provide boilerplate code for Electron applications, but angular-electron is specifically tailored for Angular integration, while electron-boilerplate offers a more general-purpose setup. The choice between the two depends on the project requirements and the developer's preference for Angular or vanilla JavaScript.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Angular Logo Electron Logo

Maintained Make a pull request License

Linux Build MacOS Build Windows Build

Watch on GitHub Star on GitHub Tweet

Introduction

Bootstrap and package your project with Angular 17 and Electron 30 (Typescript + SASS + Hot Reload) for creating Desktop applications.

Currently runs with:

  • Angular v17.3.6
  • Electron v30.0.1

With this sample, you can:

  • Run your app in a local development environment with Electron & Hot reload
  • Run your app in a production environment
  • Execute your tests with Jest and Playwright (E2E)
  • Package your app into an executable file for Linux, Windows & Mac

/!\ Hot reload only pertains to the renderer process. The main electron process is not able to be hot reloaded, only restarted.

/!\ Angular CLI & Electron Builder needs Node 18.10 or later to work correctly.

Getting Started

Clone this repository locally:

git clone https://github.com/maximegris/angular-electron.git

Install dependencies with npm (used by Electron renderer process):

npm install

There is an issue with yarn and node_modules when the application is built by the packager. Please use npm as dependencies manager.

If you want to generate Angular components with Angular-cli , you MUST install @angular/cli in npm global context. Please follow Angular-cli documentation if you had installed a previous version of angular-cli.

npm install -g @angular/cli

Install NodeJS dependencies with npm (used by Electron main process):

cd app/
npm install

Why two package.json ? This project follow Electron Builder two package.json structure in order to optimize final bundle and be still able to use Angular ng add feature.

To build for development

  • in a terminal window -> npm start

Voila! You can use your Angular + Electron app in a local development environment with hot reload!

The application code is managed by app/main.ts. In this sample, the app runs with a simple Angular App (http://localhost:4200), and an Electron window.
The Angular component contains an example of Electron and NodeJS native lib import.
You can disable "Developer Tools" by commenting win.webContents.openDevTools(); in app/main.ts.

Project structure

FolderDescription
appElectron main process folder (NodeJS)
srcElectron renderer process folder (Web / Angular)

How to import 3rd party libraries

This sample project runs in both modes (web and electron). To make this work, you have to import your dependencies the right way. \

There are two kind of 3rd party libraries :

  • NodeJS's one - Uses NodeJS core module (crypto, fs, util...)
    • I suggest you add this kind of 3rd party library in dependencies of both app/package.json and package.json (root folder) in order to make it work in both Electron's Main process (app folder) and Electron's Renderer process (src folder).

Please check providers/electron.service.ts to watch how conditional import of libraries has to be done when using NodeJS / 3rd party libraries in renderer context (i.e. Angular).

  • Web's one (like bootstrap, material, tailwind...)
    • It have to be added in dependencies of package.json (root folder)

Add a dependency with ng-add

You may encounter some difficulties with ng-add because this project doesn't use the defaults @angular-builders.
For example you can find here how to install Angular-Material with ng-add.

Browser mode

Maybe you only want to execute the application in the browser with hot reload? Just run npm run ng:serve:web.

Included Commands

CommandDescription
npm run ng:serveExecute the app in the web browser (DEV mode)
npm run web:buildBuild the app that can be used directly in the web browser. Your built files are in the /dist folder.
npm run electron:localBuilds your application and start electron locally
npm run electron:buildBuilds your application and creates an app consumable based on your operating system

Your application is optimised. Only /dist folder and NodeJS dependencies are included in the final bundle.

You want to use a specific lib (like rxjs) in electron main thread ?

YES! You can do it! Just by importing your library in npm dependencies section of app/package.json with npm install --save XXXXX.
It will be loaded by electron during build phase and added to your final bundle.
Then use your library by importing it in app/main.ts file. Quite simple, isn't it?

E2E Testing

E2E Test scripts can be found in e2e folder.

CommandDescription
npm run e2eExecute end to end tests

Note: To make it work behind a proxy, you can add this proxy exception in your terminal
export {no_proxy,NO_PROXY}="127.0.0.1,localhost"

Debug with VsCode

VsCode debug configuration is available! In order to use it, you need the extension Debugger for Chrome.

Then set some breakpoints in your application's source code.

Finally from VsCode press Ctrl+Shift+D and select Application Debug and press F5.

Please note that Hot reload is only available in Renderer process.

Want to use Angular Material ? Ngx-Bootstrap ?

Please refer to HOW_TO file

Branch & Packages version

  • Angular 4 & Electron 1 : Branch angular4
  • Angular 5 & Electron 1 : Branch angular5
  • Angular 6 & Electron 3 : Branch angular6
  • Angular 7 & Electron 3 : Branch angular7
  • Angular 8 & Electron 7 : Branch angular8
  • Angular 9 & Electron 7 : Branch angular9
  • Angular 10 & Electron 9 : Branch angular10
  • Angular 11 & Electron 12 : Branch angular11
  • Angular 12 & Electron 16 : Branch angular12
  • Angular 13 & Electron 18 : Branch angular13
  • Angular 14 & Electron 21 : Branch angular14
  • Angular 15 & Electron 24 : Branch angular15
  • Angular 16 & Electron 25 : Branch angular16
  • Angular 17 & Electron 30 : (main)