Convert Figma logo to code with AI

szwacz logoelectron-boilerplate

Boilerplate application for Electron runtime

3,126
490
3,126
3

Top Related Projects

6,405

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

A Foundation for Scalable Cross-Platform Apps

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.

Ultra-fast bootstrapping with Angular and Electron :speedboat:

7,402

:electron: 🚀 The easiest way to get started with Electron

Quick Overview

Electron Boilerplate is a minimalistic starter template for building cross-platform desktop applications using Electron, HTML, CSS, and JavaScript. It provides a solid foundation with essential features and best practices, allowing developers to quickly start creating Electron apps without worrying about initial setup and configuration.

Pros

  • Lightweight and minimalistic, focusing on essential features without bloat
  • Includes a well-structured project layout and build system
  • Supports hot reloading for faster development
  • Provides a solid starting point for both beginners and experienced developers

Cons

  • May require additional setup for more complex applications
  • Limited built-in features compared to some other Electron boilerplates
  • Might need regular updates to keep up with the latest Electron versions
  • Documentation could be more comprehensive for advanced use cases

Getting Started

  1. Clone the repository:

    git clone https://github.com/szwacz/electron-boilerplate.git
    cd electron-boilerplate
    
  2. Install dependencies:

    npm install
    
  3. Start the development server:

    npm start
    
  4. To build for production:

    npm run release
    

This will create a packaged version of your app in the dist folder, ready for distribution.

Competitor Comparisons

6,405

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

Pros of Electron Forge

  • Official Electron tooling with extensive documentation and community support
  • Integrated build and packaging tools for multiple platforms
  • Customizable project templates and flexible configuration options

Cons of Electron Forge

  • Steeper learning curve for beginners due to more advanced features
  • Potentially more complex setup process for simple projects
  • Larger project size and dependencies compared to minimal boilerplates

Code Comparison

Electron Forge (package.json):

{
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make"
  }
}

Electron Boilerplate (package.json):

{
  "scripts": {
    "start": "electron-webpack dev",
    "compile": "electron-webpack",
    "dist": "yarn compile && electron-builder"
  }
}

Electron Forge provides a more streamlined approach with built-in commands for starting, packaging, and building the application. Electron Boilerplate relies on separate tools like electron-webpack and electron-builder, requiring additional configuration.

Electron Forge offers a more comprehensive solution for Electron app development, while Electron Boilerplate provides a lightweight starting point. The choice between them depends on project requirements, developer experience, and desired level of customization.

A Foundation for Scalable Cross-Platform Apps

Pros of electron-react-boilerplate

  • Includes React and Redux out of the box, providing a robust framework for building complex UIs
  • Offers TypeScript support, enhancing code quality and developer productivity
  • Includes a more comprehensive set of development tools and configurations

Cons of electron-react-boilerplate

  • Larger initial project size due to included dependencies
  • Steeper learning curve for developers not familiar with React and Redux
  • May be overkill for simple applications that don't require a complex UI framework

Code Comparison

electron-boilerplate (main.js):

app.on('ready', () => {
  mainWindow = createWindow('main', {
    width: 1000,
    height: 600,
  });
  mainWindow.loadFile(path.join(__dirname, 'app.html'));
});

electron-react-boilerplate (main.dev.ts):

app.on('ready', createWindow);
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

The electron-react-boilerplate example uses TypeScript and has a more modular structure, with the window creation logic separated into a different file. It also includes additional event handling for improved cross-platform behavior.

Clone to try a simple Electron app

Pros of electron-quick-start

  • Simpler and more lightweight, ideal for beginners
  • Officially maintained by the Electron team
  • Focuses on the bare essentials for getting started

Cons of electron-quick-start

  • Lacks advanced features and build configurations
  • Doesn't include testing setup or production-ready optimizations
  • Limited project structure, requiring more setup for larger applications

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)

electron-boilerplate:

import { app } from 'electron';
import { createWindow } from './helpers/window';

const setAppMenu = require('./helpers/menu');
const setIpcMain = require('./helpers/ipc');

app.on('ready', () => {
  setAppMenu();
  setIpcMain();
  createWindow('main', { width: 1000, height: 600 });
});

electron-quick-start provides a minimal setup with a single file, while electron-boilerplate offers a more structured approach with separate helper files for different functionalities. The latter is better suited for larger projects requiring more organization and advanced features.

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

  • Integrates Vue.js framework, providing a robust and reactive component-based architecture
  • Includes vue-cli for easy project scaffolding and management
  • Offers built-in support for vue-router and vuex for state management

Cons of electron-vue

  • Steeper learning curve for developers not familiar with Vue.js ecosystem
  • More opinionated structure, which may limit flexibility for some projects
  • Slightly larger initial project size due to additional Vue.js dependencies

Code Comparison

electron-vue:

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

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

electron-boilerplate:

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

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

Summary

electron-vue is ideal for developers who prefer Vue.js and want a more structured, feature-rich boilerplate. It offers a complete Vue.js integration, including vue-router and vuex, making it suitable for complex applications.

electron-boilerplate provides a more minimal setup, offering greater flexibility and a lower entry barrier for developers new to Electron. It's better suited for simpler applications or those requiring a custom framework setup.

Choose based on your familiarity with Vue.js, project complexity, and desired level of structure and features.

Ultra-fast bootstrapping with Angular and Electron :speedboat:

Pros of angular-electron

  • Integrates Angular framework, providing a robust structure for large-scale applications
  • Includes TypeScript support out of the box, enhancing code quality and maintainability
  • Offers a more comprehensive set of development tools and scripts

Cons of angular-electron

  • Steeper learning curve due to Angular's complexity
  • Potentially heavier and slower startup compared to the lightweight electron-boilerplate
  • May be overkill for simple Electron applications

Code Comparison

electron-boilerplate:

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

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

angular-electron:

import { app, BrowserWindow } 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 {
  win = new BrowserWindow({ width: 800, height: 600 });
  win.loadURL(serve ? 'http://localhost:4200' : 'file://' + __dirname + '/index.html');
  return win;
}

The angular-electron boilerplate provides a more structured approach with TypeScript and additional configuration options, while electron-boilerplate offers a simpler setup for basic Electron applications.

7,402

:electron: 🚀 The easiest way to get started with Electron

Pros of Fiddle

  • More actively maintained with frequent updates
  • Includes a built-in Electron playground for quick experimentation
  • Offers a user-friendly GUI for managing Electron projects

Cons of Fiddle

  • Larger project scope, potentially more complex for beginners
  • Focused on experimentation rather than production-ready boilerplate
  • May include features not needed for simple Electron applications

Code Comparison

Fiddle (main process):

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

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

app.whenReady().then(createWindow)

Electron Boilerplate (main process):

import { app } from 'electron';
import { createWindow } from './helpers/window';

app.on('ready', () => {
  createWindow('main', { width: 1000, height: 600 });
});

Both repositories provide a starting point for Electron development, but they serve different purposes. Fiddle is geared towards experimentation and learning, offering a playground environment with a GUI. Electron Boilerplate, on the other hand, provides a more traditional boilerplate structure for building production-ready applications.

Fiddle's code tends to be more straightforward and educational, while Electron Boilerplate offers a more structured approach with separate helper functions and modules. The choice between the two depends on the developer's needs and project requirements.

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

electron-boilerplate

This repository is no longer in active maintenance.


Minimalistic, very easy to understand boilerplate for Electron runtime. Tested on Windows, macOS and Linux.

This project contains only bare minimum of tooling and dependencies to provide you with simple to understand and extensible base (but still, this is fully functional Electron environment). The boilerplate doesn't impose on you any frontend technologies, so feel free to pick your favourite.

Quick start

Make sure you have Node.js installed, then type...

git clone https://github.com/szwacz/electron-boilerplate.git
cd electron-boilerplate
npm install
npm start

...and you have a running desktop application on your screen.

Structure of the project

The application consists of two main folders...

src - files within this folder get transpiled or compiled (because Electron can't use them directly).

app - contains all static assets which don't need any pre-processing and can be used directly.

The build process compiles the content of the src folder and puts it into the app folder, so after the build has finished, your app folder contains the full, runnable application. Treat src and app folders like two halves of one bigger thing.

The drawback of this design is that app folder contains some files which should be git-ignored and some which shouldn't (see .gitignore file). But this two-folders split makes development builds much faster.

Development

Starting the app

npm start

The build pipeline

Build process uses Webpack. The entry-points are src/main.js and src/app.js. Webpack will follow all import statements starting from those files and compile code of the whole dependency tree into one .js file for each entry point.

Babel is also utilised, but mainly for its great error messages. Electron under the hood runs latest Chromium, hence most of the new JavaScript features are already natively supported.

Environments

Environmental variables are done in a bit different way (not via process.env). Env files are plain JSONs in config directory, and build process dynamically links one of them as an env module. You can import it wherever in code you need access to the environment.

import env from "env";
console.log(env.name);

Adding npm modules to your app

Remember to respect the split between dependencies and devDependencies in package.json file. Your distributable app will contain only modules listed in dependencies after running the release script.

Side note: If the module you want to use in your app is a native one (not pure JavaScript but compiled binary) you should first run npm install name_of_npm_module and then npm run postinstall to rebuild the module for Electron. You need to do this once after you're first time installing the module. Later on, the postinstall script will fire automatically with every npm install.

Testing

Run all tests:

npm test

Unit

npm run unit

Using electron-mocha test runner with the Chai assertion library. You can put your spec files wherever you want within the src directory, just name them with the .spec.js extension.

End to end

npm run e2e

Using Mocha and Spectron. This task will run all files in e2e directory with .e2e.js extension.

Making a release

To package your app into an installer use command:

npm run release

Once the packaging process finished, the dist directory will contain your distributable file.

Electron-builder is handling the packaging process. Follow docs over there to customise your build.

You can package your app cross-platform from a single operating system, electron-builder kind of supports this, but there are limitations and asterisks. That's why this boilerplate doesn't do that by default.