All Projects → yhirose → React Typescript Electron Sample With Create React App And Electron Builder

yhirose / React Typescript Electron Sample With Create React App And Electron Builder

React-TypeScript-Electron sample with Create React App and Electron Builder

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Typescript Electron Sample With Create React App And Electron Builder

React Desktops
web桌面操作系统前端UI,用了丰富的mac和win10桌面元素,包括桌面图标、窗口化子页面管理、开始菜单等组件,兼容主流现代浏览器。 适合快速开发后台管理系统的前端界面、整合企业诸多应用、通过B/S架构集成系统、可作为企业级应用管理平台。
Stars: ✭ 120 (-16.08%)
Mutual labels:  create-react-app
React Mobx State Tree
Create React App with MobX State Tree, Styled Components and GraphQL
Stars: ✭ 127 (-11.19%)
Mutual labels:  create-react-app
React Portfolio
A React portfolio starter app using create-react-app. Includes top header, side nav with a few pages which are routed with react-router
Stars: ✭ 136 (-4.9%)
Mutual labels:  create-react-app
Shadow Cljs
ClojureScript compilation made easy
Stars: ✭ 1,774 (+1140.56%)
Mutual labels:  hot-reload
Restsplain
WordPress REST API documentation generator
Stars: ✭ 126 (-11.89%)
Mutual labels:  create-react-app
Subway Shanghai
🚆上海地铁线路图PWA,支持离线使用,强烈建议安装Chrome浏览器使用。Subway Shanghai, offline first, it's strongly recommended to use by Chrome.
Stars: ✭ 130 (-9.09%)
Mutual labels:  create-react-app
Create Ueno App
The easiest and fastest way to create new web projects with next, gatsby, create-react-app and mobile projects with react-native.
Stars: ✭ 116 (-18.88%)
Mutual labels:  create-react-app
Create React Microservice
🚀 Create highly scalable and universal React microservices/applications within seconds.
Stars: ✭ 138 (-3.5%)
Mutual labels:  create-react-app
Modern Monorepo Boilerplate
Modern Monorepo Boilerplate with Lerna, TypeScript, React/CRA, HMR, Jest, ESLint/TypeScript.
Stars: ✭ 127 (-11.19%)
Mutual labels:  hot-reload
Cra Serverless
Serverless pre-rendering (SSR) for React SPA using AWS Lambda, S3, and CloudFront.
Stars: ✭ 137 (-4.2%)
Mutual labels:  create-react-app
Create React App Esbuild
Use esbuild in your create-react-app for faster compilation, development and tests
Stars: ✭ 122 (-14.69%)
Mutual labels:  create-react-app
Electron Builder
A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
Stars: ✭ 11,653 (+8048.95%)
Mutual labels:  electron-builder
Instapack
All-in-one TypeScript and Sass compiler for web applications! 📦 🚀
Stars: ✭ 131 (-8.39%)
Mutual labels:  hot-reload
Reactly Starter Kit
Deployable React + Webpack 2 starter kit
Stars: ✭ 122 (-14.69%)
Mutual labels:  hot-reload
Generator Create Redux App
Add redux, emotion-js and other useful libraries like react-router in top of create-react-app
Stars: ✭ 137 (-4.2%)
Mutual labels:  create-react-app
Flexlib
FlexLib是一个基于flexbox模型,使用xml文件进行界面布局的框架,融合了web快速布局的能力,让iOS界面开发像写网页一样简单快速
Stars: ✭ 1,569 (+997.2%)
Mutual labels:  hot-reload
Hot Reload All The Things
Starter project for HMR with backend routes and server/client-side react.
Stars: ✭ 127 (-11.19%)
Mutual labels:  hot-reload
Create React Component Folder
Creates react component folder structure
Stars: ✭ 139 (-2.8%)
Mutual labels:  create-react-app
Create React App Now
Hello, create-react-app, meet Zeit's awesome now.sh service.
Stars: ✭ 137 (-4.2%)
Mutual labels:  create-react-app
React Pages Boilerplate
Deliver react + react-router application to gh-pages
Stars: ✭ 134 (-6.29%)
Mutual labels:  hot-reload

React-TypeScript-Electron sample with Create React App and Electron Builder

This project was bootstrapped with Create React App with --typescriptoption.

On the top of it, the following features have been added with realatively small changes:

  • TypeScript supports for Electron main process source code
  • Hot-relaod support for Electron app
  • Electron Bulder support

Available Scripts in addition to the existing ones

npm run electron:dev

Runs the Electron app in the development mode.

The Electron app will reload if you make edits in the electron directory.
You will also see any lint errors in the console.

npm run electron:build

Builds the Electron app package for production to the dist folder.

Your Electron app is ready to be distributed!

Project directory structure

my-app/
├── package.json
│
## render process
├── tsconfig.json
├── public/
├── src/
│
## main process
├── electron/
│   ├── main.ts
│   └── tsconfig.json
│
## build output
├── build/
│   ├── index.html
│   ├── static/
│   │   ├── css/
│   │   └── js/
│   │
│   └── electron/
│      └── main.js
│
## distribution packges
└── dist/
    ├── mac/
    │   └── my-app.app
    └── my-app-0.1.0.dmg

Do it yourself from scratch

Generate a React project and install npm dependencies

create-react-app my-app --typescript
cd my-app
yarn add @types/electron-devtools-installer electron-devtools-installer electron-is-dev electron-reload
yarn add -D concurrently electron electron-builder wait-on

Make Electron main process source file

electron/tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "strict": true,
    "outDir": "../build", // Output transpiled files to build/electron/
    "rootDir": "../",
    "noEmitOnError": true,
    "typeRoots": [
      "node_modules/@types"
    ]
  }
}

electron/main.ts

import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import * as isDev from 'electron-is-dev';
import installExtension, { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer";

let win: BrowserWindow | null = null;

function createWindow() {
  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  if (isDev) {
    win.loadURL('http://localhost:3000/index.html');
  } else {
    // 'build/index.html'
    win.loadURL(`file://${__dirname}/../index.html`);
  }

  win.on('closed', () => win = null);

  // Hot Reloading
  if (isDev) {
    // 'node_modules/.bin/electronPath'
    require('electron-reload')(__dirname, {
      electron: path.join(__dirname, '..', '..', 'node_modules', '.bin', 'electron'),
      forceHardReset: true,
      hardResetMethod: 'exit'
    });
  }

  // DevTools
  installExtension(REACT_DEVELOPER_TOOLS)
    .then((name) => console.log(`Added Extension:  ${name}`))
    .catch((err) => console.log('An error occurred: ', err));

  if (isDev) {
    win.webContents.openDevTools();
  }
}

app.on('ready', createWindow);

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

app.on('activate', () => {
  if (win === null) {
    createWindow();
  }
});

Adjust package.json

Add properties for Electron

  "homepage": ".", # see https://create-react-app.dev/docs/deployment#serving-the-same-build-from-different-paths
  "main": "build/electron/main.js",

Add properties for Electron Builder

  "author": "Your Name",
  "description": "React-TypeScript-Electron sample with Create React App and Electron Builder",
  ...
  "build": {
    "extends": null, # see https://github.com/electron-userland/electron-builder/issues/2030#issuecomment-386720420
    "files": [
      "build/**/*"
    ],
    "directories": {
      "buildResources": "assets" # change the resource directory from 'build' to 'assets'
    }
  },

Add scripts

  "scripts": {
    "postinstall": "electron-builder install-app-deps",
    "electron:dev": "concurrently \"BROWSER=none yarn start\" \"wait-on http://localhost:3000 && tsc -p electron -w\" \"wait-on http://localhost:3000 && tsc -p electron && electron .\"",
    "electron:build": "yarn build && tsc -p electron && electron-builder",

Many thanks to the following articles!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].