Skip to content

Commit

Permalink
Add a new example (remote-require) :)
Browse files Browse the repository at this point in the history
  • Loading branch information
saltyshiomix committed Sep 1, 2019
1 parent 8107b0a commit bf41d02
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ $ yarn create nextron-app my-app --example parameterized-routing

<p align="center"><img src="https://i.imgur.com/LvPIeIj.png"></p>

### [examples/remote-require](./examples/remote-require)

```bash
# with `nextron`
$ nextron init my-app --example remote-require

# with npx
$ npx create-nextron-app my-app --example remote-require

# with yarn
$ yarn create nextron-app my-app --example remote-require
```

<p align="center"><img src="https://i.imgur.com/9fdMREj.png"></p>

### [examples/store-data](./examples/store-data)

```bash
Expand Down
31 changes: 31 additions & 0 deletions examples/remote-require/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<p align="center"><img src="https://i.imgur.com/9fdMREj.png"></p>

## Usage

### Create an App

```bash
# with `nextron`
$ nextron init my-app --example remote-require

# with npx
$ npx create-nextron-app my-app --example remote-require

# with yarn
$ yarn create nextron-app my-app --example remote-require
```

### Use it

```bash
$ cd my-app

# Install dependencies
$ yarn (or `npm install`)

# Run development mode
$ yarn dev (or `npm run dev`)

# Build packages
$ yarn build (or `npm run build`)
```
12 changes: 12 additions & 0 deletions examples/remote-require/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appId: com.example.nextron
productName: My Nextron App
copyright: Copyright © 2018 Yoshihide Shiono
directories:
output: dist
buildResources: resources
files:
- from: .
filter:
- package.json
- app
publish: null
5 changes: 5 additions & 0 deletions examples/remote-require/main/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = {
message: 'This message is from the main process of `config.js`',
};

export default config;
8 changes: 8 additions & 0 deletions examples/remote-require/nextron.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
webpack: (defaultConfig, env) => Object.assign(defaultConfig, {
entry: {
background: './main/background.js',
config: './main/config.js',
},
}),
};
25 changes: 25 additions & 0 deletions examples/remote-require/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"private": true,
"name": "my-nextron-app",
"description": "My application description",
"version": "1.0.0",
"author": "Yoshihide Shiono <shiono.yoshihide@gmail.com>",
"main": "app/background.js",
"scripts": {
"dev": "nextron",
"build": "nextron build",
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
"electron-serve": "^0.3.0",
"electron-store": "^4.0.0"
},
"devDependencies": {
"electron": "^6.0.7",
"electron-builder": "^21.2.0",
"next": "^9.0.5",
"nextron": "^5.9.2",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
}
5 changes: 5 additions & 0 deletions examples/remote-require/renderer/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
webpack: (config) => Object.assign(config, {
target: 'electron-renderer',
}),
};
40 changes: 40 additions & 0 deletions examples/remote-require/renderer/pages/home.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import electron from 'electron';
import React, { useState, useEffect } from 'react';
import Head from 'next/head';
import Link from 'next/link';

// prevent SSR webpacking
const remote = electron.remote || false;

const Home = () => {
const [config, setConfig] = useState({});

useEffect(() => {
// componentDidMount()
if (remote) {
setConfig(remote.require('./config').default);
}

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

return (
<React.Fragment>
<Head>
<title>Home - Nextron (remote-require)</title>
</Head>
<p>
⚡ Electron + Next.js ⚡ -
<Link href="/next">
<a>Go to next page</a>
</Link>
</p>
<hr/>
<p>{config.message}</p>
</React.Fragment>
);
};

export default Home;
21 changes: 21 additions & 0 deletions examples/remote-require/renderer/pages/next.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import Head from 'next/head';
import Link from 'next/link';

const Next = () => {
return (
<React.Fragment>
<Head>
<title>Next - Nextron (remote-require)</title>
</Head>
<p>
⚡ Electron + Next.js ⚡ -
<Link href="/home">
<a>Go to home page</a>
</Link>
</p>
</React.Fragment>
);
};

export default Next;

0 comments on commit bf41d02

Please sign in to comment.