I'd be curious what module requires your main
to be a JS file. It's pretty rare that you'd have an NW.js project that doesn't use an html file as the main
(I strongly recommend using "main": "index.html"
).
Your problem is that var nw = require('nwjs');
is equivalent to doing nw = undefined
. window.nw
and global.nw
are both already accessible at all times in the default context. You are basically deleting the thing you need.
index.html
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body>
<h1>Test<h1>
</body>
</html>
index.js
nw.Window.open('index.html');
package.json
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "nw ."
},
"devDependencies": {
"nw": "0.51.0-sdk"
},
"author": "Julien",
"description": "Test",
"license": "MIT"
}
Then just npm install && npm start
. But again, you don't want this, you want "main": "index.html"
, it's just a lot less trouble.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…