我正在尝试使用 nw.js 打包桌面应用程序。 应用程序导航到由 xampp 服务器提供服务的页面,该服务器位于应用程序运行的同一台计算机上。
当 nw.js 通过 file://导航到页面时,脚本加载成功。
当它通过 http://导航时,脚本不会加载。
控制台中的错误是:
Uncaught ReferenceError: require is not defined
我该如何解决这个问题?我需要它通过 http 加载,因为该应用程序使用 php 来实现几个基本功能。
最佳答案
这是一个使用 Node 远程的示例。
package.json
{
"main": "http://localhost:3030/",
"name": "nw-demo",
"description": "demo app of node-webkit",
"version": "0.1.0",
"node-remote" : "localhost:3030",
"window": {
"title": "node-webkit demo",
"toolbar": true,
"frame": true,
"position": "center"
}
}
本地主机上的 html 文件
<script>document.write(require, process);</script>
nwjs (v0.12.3) 应用输出
function (name) { if (name == 'nw.gui') return nwDispatcher.requireNwGui(); return global.require(name); }[object process]
关于javascript - 如何在 NW.js 的服务页面中运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34733540/