Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

nx-electron

bennymeg54.7kApache-2.021.0.1TypeScript support: included

Electron Plugin for Nx

nx, electron, forge, package, make, bundle, monorepo, schematics, generators, builders, executors

readme

Nx Electron

Electron builders and schematics for Nrwl Nx platform.

License NPM Version Downloads Sponsor Star this repo



Features

Nx Electron provides a set of power ups on Nx for developing cross platform desktop apps using Electron.

  • Schematics: Provides schematics for developing cross platform apps in a mono repo environment.
  • Typescript: Uses Typescript to help reduce errors, and create more structured code.
  • Obfuscation: Since Electron are used on the client machines, nx-electron obfuscates you code (and only it).
  • Minimization: Electron apps tend to be quite large, hence we use webpack to bundle, and minimize to code.
  • Live Update: Provides continuous live reload for your backend code.
  • Event Templates: Provides templates for common events like squirrel setup events, auto update events and IPC events.
  • Packaging: Packages your frontend and backend webpack bundles into an electron package.
  • Making: Makes your frontend and backend webpack bundles into single standalone executable.

Compatibility

[!IMPORTANT] This repository follows the semantic versioning rules while adhering to both Nx and Angular versioning scheme. Make sure that Nx Electron major version match Nx major version. I.e. version 21.x of Nx Electron will be compatible with version 21.y of Nx.

Getting Started

Prerequisite

This module is based on Nx, you will need to set up an Nx workspace before you can use Nx Electron.

npx create-nx-workspace@21

Installation

npm install -D nx-electron

Creating Nx Electron Application

nx g nx-electron:app <electron-app-name> --frontendProject=<frontend-app-name>

[!IMPORTANT] Make sure to select Integrated monorepo as a project style, and Webpack as a bundler.

[!NOTE] You should add a frontend project to you workspace prior to invoking this command.

[!TIP] On certain frontend platforms (such as Angular, React, etc...) it is important to:

  1. change the baseHref field to "./".
  2. Use router outlet hash strategy. Further details can be found here.

[!NOTE] Nx Electron application usually contain both frontend and backend. When you wish to build, serve, test, etc. your application, make sure to invoke the command for both the frontend and the backend. Most of the the time, side-by-side terminal windows are more convenient.

Building Nx Electron Application

  • Frontend: Run nxe:build:frontend or nx build <frontend-app-name> to build your frontend application.
  • Backend: Run nxe:build:backend or nx build <electron-app-name> to build your backend application.

Serving Nx Electron Application

  • Frontend: Run nxe:serve:frontend or nx serve <frontend-app-name> to serve your frontend application.
  • Backend: Run nxe:serve:backend or nx serve <electron-app-name> to serve your backend application.

Testing Nx Electron Application

  • Frontend: Run nxe:test:frontend or nx test <frontend-app-name> to test your frontend application.
  • Backend: Run nxe:test:backend or nx test <electron-app-name> to test your backend application.

Packaging Nx Electron Application

  • Run nxe:package:app or nx run <electron-app-name>:package [--options] to package your application.

    The options that can be passed are described here.

    [!IMPORTANT] Make sure to build both the frontend project and the backend project before packaging your application.

Making Nx Electron Application (standalone build)

  • Run nxe:make:app or nx run <electron-app-name>:make [--options] to make your standalone application.

    The options that can be passed are described here.

    [!IMPORTANT] Make sure to build both the frontend project and the backend project before making your standalone application.

Configuring static packaging / making options

It is possible to configure all the packaging / making options in .\apps\<electron-app-name>\src\app\options\maker.options.json. For more information read this article.

[!IMPORTANT] Option you define at this file will override the options you pass manually via the command line or choose via the angular console.

Migrating Nx Electron Application

To migrate automatically run ng update nx-electron@<version>. You can find detailed information in the following migration guides.

Debugging Nx Electron Application

Minimal Project Structure

Regardless of what framework you chose, the resulting file tree will look like this:

<workspace name>/
├── apps/
│   ├── electron-app-name/
│   ├── frontend-app-name/
│   └── frontend-app-name-e2e/
├── libs/
├── tools/
├── nx.json
├── package.json
├── tsconfig.json
└── tslint.json

Support

If you're having any problem, please raise an issue on GitHub and we'll be happy to help.

Contribute

Attribution

This project is highly inspired by (and dependent on) Nrwl Nx platform. Under the hood, we use Electron Builder to package and make electron application executables.



Author: Benny Megidish.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

14.0.2 (2023-02-01)

Bug Fixes

  • removed unused dependencies from v13 (ab450d8)

14.0.0 (2023-02-01)

Features

Bug Fixes

13.2.3 (2023-01-08)

13.2.2 (2023-01-08)

Bug Fixes

13.2.1 (2022-06-01)

13.2.0 (2022-06-01)

Features

Bug Fixes

13.1.0 (2022-05-16)

Features

  • added multiple preload scripts support #155 (1adc422)
  • do not generate package json while serving (209702f)
  • migrate generate package json (b0d839f)
  • package: add option for overriding maker options file #151 (198c22c)
  • serve: added rederer debugging port option #136 (8958f32)

Bug Fixes

  • app init asset folder generation (bbe1661)
  • app init asset folder generation (4acace3)
  • app init asset folder generation (2) (801f653)
  • deps audit (22d8d00)
  • empty maker option path (d659149)
  • remove file extension from preload webpack entry (b23abba)
  • temporarly added angular-devkit (6abd615)
  • updated path delimeters for consistency (5e90a9f)

12.1.0 (2022-02-04)

Features

Bug Fixes

12.0.0 (2021-11-24)

Features

Bug Fixes