• Stars
    star
    3,908
  • Rank 11,200 (Top 0.3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚡ Next.js + Electron ⚡

NPM version NPM downloads Package License (MIT) AWESOME NEXTJS

Support

Nextron vs Next.js

nextron next
v9.x v13.x (upcoming)
v8.x v12.x
v7.x v11.x
v6.x v10.x
v5.x v9.x
v4.x v8.x
v2.x / v3.x v7.x
v1.x v6.x

Package Manager

npm, yarn and pnpm are supported.

My Belief for Nextron

  1. Show a way of developing desktop apps with only web knowledge
  2. Easy to use
  3. Be transparent and open to OSS developers

Usage

Create Application with Template

We can use examples/* as a template.

To create the examples/with-material-ui, run the command below:

# with npx
$ npx create-nextron-app MY_APP --example with-material-ui

# with yarn
$ yarn create nextron-app MY_APP --example with-material-ui

# with pnpx
$ pnpx create-nextron-app MY_APP --example with-material-ui

For nextron v8 or below, please specify --branch option:

npx create-nextron-app MY_APP --example with-material-ui --branch release/v8

Run Electron with Development Mode

Run npm run dev, and nextron automatically launches an electron app.

{
  "scripts": {
    "dev": "nextron"
  }
}

Production Build

Run npm run build, and nextron outputs packaged bundles under the dist folder.

{
  "scripts": {
    "build": "nextron build"
  }
}

Build Options

To build Windows 32 bit version, run npm run build:win32 like below:

{
  "scripts": {
    "build": "nextron build",
    "build:all": "nextron build --all",
    "build:win32": "nextron build --win --ia32",
    "build:win64": "nextron build --win --x64",
    "build:mac": "nextron build --mac --x64",
    "build:linux": "nextron build --linux"
  }
}

CAUTION: To build macOS binary, your host machine must be macOS!

Build Configuration

Edit electron-builder.yml properties for custom build configuration.

appId: com.example.nextron
productName: My Nextron App
copyright: Copyright © 2020 Yoshihide Shiono
directories:
  output: dist
  buildResources: resources
files:
  - from: .
    filter:
      - package.json
      - app
publish: null # see https://www.electron.build/configuration/publish

For more information, please check out electron-builder official configuration documents.

nextron.config.js

module.exports = {
  // specify an alternate main src directory, defaults to 'main'
  mainSrcDir: 'main',
  // specify an alternate renderer src directory, defaults to 'renderer'
  rendererSrcDir: 'renderer',

  // main process' webpack config
  webpack: (config, env) => {
    // do some stuff here
    return config;
  },
};

Custom Babel Config for the Main Process

We can extends the default babel config of main process by putting .babelrc in our project root like this:

.babelrc:

{
  "presets": [
    "nextron/babel"
  ]
}

Tips

Next.js' Webpack Processes

There are two webpack processes: server process and client one.

If we want to use some libraries that don't support SSR, we should check if the current process is whether server or client:

// pages/home.jsx

import electron from 'electron';

const Home = () => {
  // we can't use `electron.ipcRenderer` directly!
  const ipcRenderer = electron.ipcRenderer;

  // we should check it like this
  const ipcRenderer = electron.ipcRenderer || false;
  if (ipcRenderer) {
    // we can use `electron.ipcRenderer`
    // because this scope is the client webpack process
  }
};

export default Home;

The Basic of React Hooks :)

As mentioned above, we should check if the webpack process is a client because the renderer process is a web client:

// pages/home.jsx

import electron from 'electron';
import React from 'react';

const Home = () => {
  // In this scope, both of server and client processes are running
  // So if the process is server, `window` object is undefined

  React.useEffect(() => {
    // componentDidMount() like

    // In this scope, only the client process is running
    window.alert('wow');

    return () => {
      // componentWillUnmount() like
    };
  }, []);

  return <p>Hello Nextron</p>;
};

export default Home;

Examples

See examples folder for more information.

examples/basic-javascript

# with npx
$ npx create-nextron-app my-app --example basic-javascript

# with yarn
$ yarn create nextron-app my-app --example basic-javascript

# with pnpx
$ pnpx create-nextron-app my-app --example basic-javascript

examples/basic-typescript

# with npx
$ npx create-nextron-app my-app --example basic-typescript

# with yarn
$ yarn create nextron-app my-app --example basic-typescript

# with pnpx
$ pnpx create-nextron-app my-app --example basic-typescript

examples/custom-build-options

# with npx
$ npx create-nextron-app my-app --example custom-build-options

# with yarn
$ yarn create nextron-app my-app --example custom-build-options

# with pnpx
$ pnpx create-nextron-app my-app --example custom-build-options

examples/custom-main-entry

# with npx
$ npx create-nextron-app my-app --example custom-main-entry

# with yarn
$ yarn create nextron-app my-app --example custom-main-entry

# with pnpx
$ pnpx create-nextron-app my-app --example custom-main-entry

examples/custom-renderer-port

# with npx
$ npx create-nextron-app my-app --example custom-renderer-port

# with yarn
$ yarn create nextron-app my-app --example custom-renderer-port

# with pnpx
$ pnpx create-nextron-app my-app --example custom-renderer-port

examples/ipc-communication

# with npx
$ npx create-nextron-app my-app --example ipc-communication

# with yarn
$ yarn create nextron-app my-app --example ipc-communication

# with pnpx
$ pnpx create-nextron-app my-app --example ipc-communication

examples/store-data

# with npx
$ npx create-nextron-app my-app --example store-data

# with yarn
$ yarn create nextron-app my-app --example store-data

# with pnpx
$ pnpx create-nextron-app my-app --example store-data

examples/with-ant-design

# with npx
$ npx create-nextron-app my-app --example with-ant-design

# with yarn
$ yarn create nextron-app my-app --example with-ant-design

# with pnpx
$ pnpx create-nextron-app my-app --example with-ant-design

examples/with-emotion

# with npx
$ npx create-nextron-app my-app --example with-emotion

# with yarn
$ yarn create nextron-app my-app --example with-emotion

# with pnpx
$ pnpx create-nextron-app my-app --example with-emotion

examples/with-material-ui

# with npx
$ npx create-nextron-app my-app --example with-material-ui

# with yarn
$ yarn create nextron-app my-app --example with-material-ui

# with pnpx
$ pnpx create-nextron-app my-app --example with-material-ui

examples/with-tailwindcss

# with npx
$ npx create-nextron-app my-app --example with-tailwindcss

# with yarn
$ yarn create nextron-app my-app --example with-tailwindcss

# with pnpx
$ pnpx create-nextron-app my-app --example with-tailwindcss

Develop

Basic

$ git clone https://github.com/saltyshiomix/nextron.git
$ cd nextron
$ pnpm install
$ pnpm dev # default is examples/basic-javascript

Developing examples/*

$ pnpm dev <EXAMPLE-FOLDER-NAME>

Maintainers

For more information, please see Looking for maintainers #244.

Related

License

This project is licensed under the terms of the MIT license.

More Repositories

1

ark

An easiest authentication system on top of NestJS, TypeORM, NEXT.js(v9.3) and Material UI(v4).
TypeScript
257
star
2

react-ssr

React SSR as a view template engine
TypeScript
251
star
3

nuxtron

⚡ Nuxt.js + Electron ⚡
TypeScript
219
star
4

create-nextron-app

Create nextron (NEXT.js + Electron) apps in one command ⚡
JavaScript
60
star
5

webpack-typescript-react-starter

Webpack + TypeScript + React = ❤️
JavaScript
59
star
6

nest-crawler

An easiest crawling and scraping module for NestJS
TypeScript
56
star
7

nestpress

A production ready personal blogging system on top of NestJS and NEXT.js
TypeScript
41
star
8

rollup-typescript-react-starter

Rollup + TypeScript + React = ❤️
JavaScript
39
star
9

nextjs-redux-todo-app

A minimal todo app with NEXT.js on the redux architecture
TypeScript
28
star
10

react-ssr-nestjs-starter

An example of @react-ssr/nestjs-express
TypeScript
23
star
11

gfm-preview

Preview your markdown with GitHub API in real time 🎉
JavaScript
19
star
12

web-master

Web mastering tools for my personal services
TypeScript
13
star
13

nerv-ie8-boilerplate

A minimalistic boilerplate of NervJS with IE8+ and React 16 compatibility ⚡
JavaScript
10
star
14

markdown-viewer-for-firefox

[NO MAINTENANCED] GitHub flavored Markdown Viewer for **OLD** Firefox
CSS
10
star
15

LGTMify-extension

Looks Good To Me <3
TypeScript
10
star
16

tiny-pro-tips-for-windows

Tiny but pro tips for Windows
9
star
17

node-npx

A tiny npx alternative for Node.js, which executes local npm package binaries
TypeScript
7
star
18

vue-jwt-auth-example

A starter example of Vue + Vuex + JWT Authentication
TypeScript
6
star
19

editify

A pure implementation of WYSIWYG HTML editor all we needed
TypeScript
5
star
20

resolve-as-bin

Resolve a local npm package as the absolute binary path
TypeScript
5
star
21

yark

Yet another easiest authentication system on top of NestJS, prisma2, react-ssr and Material UI
TypeScript
4
star
22

viteron

⚡ vite + electron ⚡
TypeScript
4
star
23

objectio

A JavaScript object getter and setter with string literals ⚡
TypeScript
3
star
24

react-ssr-jsx-starter

An example of @react-ssr/express
JavaScript
3
star
25

react-ssr-tsx-starter

An example of @react-ssr/express
TypeScript
3
star
26

react-ssr-redux-todo-app

A redux todo example on top of @react-ssr/express
TypeScript
2
star
27

saltyshiomix

1
star
28

create-viteron-app

Create viteron (vite + electron) apps in one command ⚡
JavaScript
1
star