如何在NW.js中的服务页面中运行脚本?

时间:2016-01-12 00:19:55

标签: javascript node.js nw.js

我正在尝试使用nw.js打包桌面应用程序。 应用程序导航到正在运行应用程序的同一台计算机上的xampp服务器提供的页面。

当nw.js通过file://导航到页面时,脚本会成功加载。

当它通过http://导航时,脚本不会加载。

控制台中的错误是:

Uncaught ReferenceError: require is not defined

我该如何解决这个问题?我需要它通过http加载,因为该应用程序使用PHP的几个基本功能。

1 个答案:

答案 0 :(得分:1)

以下是node-remote的示例。

的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"
  }
}

localhost上的html文件

<script>document.write(require, process);</script>

nwjs(v0.12.3)app output

  

function(name){if(name =='nw.gui')return nwDispatcher.requireNwGui(); return global.require(name); } [对象过程]