Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(next): add routing #51

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ updates:
npm:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: "weekly"
day: "saturday"
groups:
gha:
patterns:
- "*"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ Build application:
```shell
npm run bld
```

## Accessing NW.js inside Next application

If you are trying to call `nw.require` function, Next will fail and say that
Empty file removed hooks/post-nw.js
Empty file.
7 changes: 0 additions & 7 deletions hooks/pre-nw.js

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
"dev": "concurrently -k npm:dev:website npm:dev:desktop",
"dev:website": "next dev -p 4000",
"dev:desktop": "wait-on http-get://localhost:4000 && nwbuild --mode=run --version=0.72.0 --flavor=sdk --no-glob .",
"bld": "npm run bld:website && node ./hooks/pre-nw.js && npm run bld:desktop",
"bld": "npm run bld:website && npm run bld:desktop",
"bld:website": "next build",
"bld:desktop": "nwbuild --mode=build --version=0.72.0 --flavor=sdk --no-glob --outDir=./build/desktop .next"
},
"engines": {
"node": ">= 19.3.0"
"bld:desktop": "nwbuild --mode=build --version=0.72.0 --flavor=sdk --outDir=./build/desktop --managedManifest=./package.nw.json --glob=false .next"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.1.0",
Expand All @@ -27,6 +24,10 @@
"react-dom": "^18.2.0",
"wait-on": "^7.2.0"
},
"engines": {
"node": "19.3.0"
},
"packageManager": "npm@10.3.0",
"eslintConfig": {
"env": {
"browser": true,
Expand All @@ -50,4 +51,4 @@
}
}
}
}
}
19 changes: 14 additions & 5 deletions pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React from "react";
function useNW () {
if (typeof nw !== "undefined") {
return nw;
} else {
return null;
}
}

function App() {

const nw = useNW();

return (
<div>
NW.js Next.js Example
<br />
<ul>
<li>NW.js: {nw.require('process').version['nw']}</li>
<li>Chromium: {nw.require('process').version['chromium']}</li>
<li>Node.js: {nw.require('process').version['node']}</li>
<li>V8: {nw.require('process').version['v8']}</li>
<li>NW.js: {nw && nw.require('node:process').versions['nw']}</li>
Copy link
Contributor Author

@ayushmanchhabra ayushmanchhabra Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During development, this works fine. But after building web app, the code after nw && is stripped out by the compiler. Ideally, we don't want this to happen. Maybe the way is to not bundle and minify web apps and run them as is?

<li>Chromium: {nw && nw.require('node:process').versions['chromium']}</li>
<li>Node.js: {nw && nw.require('node:process').versions['node']}</li>
<li>V8: {nw && nw.require('node:process').versions['v8']}</li>
</ul>
</div>
);
Expand Down