Nextron

Next.js + Electron

README


nextron


Support


Nextron vs Next.js


nextronnext
---------------------------------
`v9.x``v13.x`
`v8.x``v12.x`
`v7.x``v11.x`
`v6.x``v10.x`
`v5.x``v9.x`
`v4.x``v8.x`
`v2.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
1. Easy to use
1. Be transparent and open to OSS developers

Usage


Create Application with Template


We can use examples/* as a template.

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

  1. ```
  2. # with npx
  3. $ npx create-nextron-app MY_APP --example with-tailwindcss

  4. # with yarn
  5. $ yarn create nextron-app MY_APP --example with-tailwindcss

  6. # with pnpm
  7. $ pnpm dlx create-nextron-app MY_APP --example with-tailwindcss
  8. ```

Run Electron with Development Mode


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

  1. ```json
  2. {
  3.   "scripts": {
  4.     "dev": "nextron"
  5.   }
  6. }
  7. ```

Production Build


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

  1. ```json
  2. {
  3.   "scripts": {
  4.     "build": "nextron build"
  5.   }
  6. }
  7. ```

nextron or nextron dev Options


--renderer-port (default: 8888)


It specifies next dev server port:

  1. ```json
  2. {
  3.   "scripts": {
  4.     "dev": "nextron --renderer-port 7777"
  5.   }
  6. }
  7. ```

--run-only (default: undefined)


It suppresses hot reloading of the main process:

  1. ```json
  2. {
  3.   "scripts": {
  4.     "dev": "nextron --run-only"
  5.   }
  6. }
  7. ```

--startup-delay (default: 0)


It waits until renderer process is ready (milliseconds):

  1. ```json
  2. {
  3.   "scripts": {
  4.     "dev": "nextron --startup-delay 3000"
  5.   }
  6. }
  7. ```

--electron-options (default: undefined)


We can pass electron args via --electron-options:

  1. ```json
  2. {
  3.   "scripts": {
  4.     "dev": "nextron --electron-options=\"--no-sandbox\"
  5.   }
  6. }
  7. ```

nextron build Options


NOTE:

- To build macOS binary, your host machine must be macOS!
- Please consider to use electron-builder.yml instead of these CLI options.

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

  1. ```json
  2. {
  3.   "scripts": {
  4.     "build": "nextron build",
  5.     "build:mac": "nextron build --mac",
  6.     "build:mac:universal": "nextron build --mac --universal",
  7.     "build:linux": "nextron build --linux",
  8.     "build:win32": "nextron build --win --ia32",
  9.     "build:win64": "nextron build --win --x64"
  10.   }
  11. }
  12. ```

--config (default: ./electron-builder.yml)


  1. ```json
  2. {
  3.   "scripts": {
  4.     "build": "nextron build --config ./configs/electron-builder.prod.yml"
  5.   }
  6. }
  7. ```

--publish (default: undefined)


Note

Highly recommend to use electron-builder.yml:

https://www.electron.build/configuration/publish

--no-pack (default: undefined)


This option skips packaging by electron-builder:

  1. ```json
  2. {
  3.   "scripts": {
  4.     "build": "nextron build --no-pack"
  5.   }
  6. }
  7. ```

Build Configuration: electron-builder.yml


Edit electron-builder.yml for custom build configurations:

  1. ```yml
  2. appId: com.example.nextron
  3. productName: My Nextron App
  4. copyright: Copyright © 2020 Yoshihide Shiono
  5. directories:
  6.   output: dist
  7.   buildResources: resources
  8. files:
  9.   - from: .
  10.     filter:
  11.       - package.json
  12.       - app
  13. publish: null # see https://www.electron.build/configuration/publish
  14. ```

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

Custom Config: nextron.config.js


  1. ```js
  2. module.exports = {
  3.   // specify an alternate main src directory, defaults to 'main'
  4.   mainSrcDir: 'main',
  5.   // specify an alternate renderer src directory, defaults to 'renderer'
  6.   rendererSrcDir: 'renderer',

  7.   // main process' webpack config
  8.   webpack: (config, env) => {
  9.     // do some stuff here
  10.     return config
  11.   },
  12. }
  13. ```

Custom Babel Config for Main Process


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

.babelrc:

  1. ```json
  2. {
  3.   "presets": ["nextron/babel"]
  4. }
  5. ```

Examples


See examples folder for more information.

  1. ```
  2. # with npx
  3. $ npx create-nextron-app my-app --example basic-lang-javascript

  4. # with yarn
  5. $ yarn create nextron-app my-app --example basic-lang-javascript

  6. # with pnpm
  7. $ pnpm dlx create-nextron-app my-app --example basic-lang-javascript
  8. ```

examples/basic-lang-typescript


  1. ```
  2. # with npx
  3. $ npx create-nextron-app my-app --example basic-lang-typescript

  4. # with yarn
  5. $ yarn create nextron-app my-app --example basic-lang-typescript

  6. # with pnpm
  7. $ pnpm dlx create-nextron-app my-app --example basic-lang-typescript
  8. ```

examples/basic-launch-app-from-url


This example shows how to open your app from browser URL.

Note: this example works only production build!

  1. ```
  2. # with npx
  3. $ npx create-nextron-app my-app --example basic-launch-app-from-url

  4. # with yarn
  5. $ yarn create nextron-app my-app --example basic-launch-app-from-url

  6. # with pnpm
  7. $ pnpm dlx create-nextron-app my-app --example basic-launch-app-from-url

  8. # --------------------------------------------------------------

  9. # Production build
  10. $ yarn build (or `npm run build` or `pnpm run build`)
  11. ```

After production build, open your-custom-protocol://open?token=jwt-value in your browser, then the app will be shown like a magic!

If you want to change schema URL, please edit electron-builder.yml#protocols:

  1. ```yml
  2. protocols:
  3.   name: Your App Name
  4.   schemes: [your-custom-protocol-edited]
  5. ```

Then, you can see the app from URL: your-custom-protocol-edited://any-uri-here?data=include-any-data.