npm - 如何打开两个单独的 nw.js 应用程序
问题描述
我正在构建一个服务器和一个客户端 nwjs 应用程序,但我无法同时打开两者。我想知道是否有任何方法可以做到这一点。我npm run dev
在我打开的两个 VS Code 上运行,但是当我在第二个应用程序上运行此命令时,它根本不会打开(无论哪个是我想运行的第二个应用程序)。我尝试构建客户端应用程序并运行它,在它运行服务器应用程序但它是相同的之后,第二个应用程序将无法启动。
这是我在两个应用程序中的 package.json 文件,我不知道这是否有帮助。只有应用程序中的名称不同(nwjs_client 和 nwjs_server)
{
"name": "nwjs_server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nw src/",
"prod": "nwbuild --platforms win32,win64,osx64,linux32,linux64 --buildDir dist/ src/"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nw": "^0.49.1"
}
}
我愿意接受任何答案,我什至不知道是否可以运行 2 个不同的 nwjs 应用程序。
解决方案
I'm confused by what you are trying to do.
- If you are trying to run an NW.js that, instead of loading directly from a
index.html
, it loads displays a page from a local webserver:- Create an
server.js
that spins up a local web server on a specific port (like4263
or something not super common). - If you need any node_modules for this (like
express
) make sure it is adependency
and not adevDependency
. - Set your
"main"
in thepackage.json
to"http://localhost:4263
using the same port as the server - set your
"node-main"
to"server.js"
, this will run in the node context before your window is displayed when starting the app. - Set your
"node-remote"
to"http://localhost:4263"
using the same port also. This will allow Node commands to run on that URL when loaded in NW.js.
- Create an
- If you are wanting to run two commands at the same time you can:
npm install --save-dev concurrently wait-on
. This will install two devDeps- Set your npm script to
"start": "concurrently \"npm run serve\" \"wait-on http://localhost:4263 && nw .\""
- This will run your
npm run serve
command, which presumably spins up a local webserver for development, if using something like webpack, this could take a minute. Then it waits untillocalhost:4263
actually returns a response. Then it launches NW.js
concurrently will also let you run any two (or more) commands at the same time.
推荐阅读
- c# - 类中的 Dispatcher.invoke 问题:C#
- r - R Shiny App-数据表输出未呈现
- python - Is tensorflow session running in parallel to the rest of my code?
- c# - ML.NET, "Score Column" is missing
- r - mlr / parallelMap: How to pass libPaths to workers when working with checkpoint?
- .htaccess - htaccess redirect url with parameter variables
- go - Parse full email address included name
- css - How do I to add a css class on wordpress?
- sql - liquibase databasechangelog table in updateSql mode
- sql-server - TSQL Performance Issues with SYS tables