[英]Electron with React: how to setup production webserver
I have electron app which loads React app runing on webpack-dev-server on port 8080. React app is communicating with node server app on port 9001. How can I setup webserver in production? 我有电子应用程序,该应用程序加载运行在端口8080上的webpack-dev-server上的React应用程序。Reactapp正在与端口9001上的节点服务器应用程序进行通信。如何在生产中设置Webserver? What I'm trying now is instal node separately via postinstall script.
我现在要尝试的是通过安装后脚本分别安装节点。 So electron use own packaged version of node and webpack-dev-server use another version of node, installed via script.
因此,electron使用自己的节点打包版本,而webpack-dev-server使用通过脚本安装的另一版本的节点。 I feel this is not the right way.
我觉得这不是正确的方法。 How can I use electron's version of node for webpack-dev-server?
我如何在webpack-dev-server中使用电子版的node? Is it possible to make it to use only the packaged version of node both for electron and webpack-dev-server?
是否有可能使其仅对电子版和webpack-dev-server使用节点的打包版本? Thanks
谢谢
The idea of installing node via deb dependency is not good due to postinstallation issues on windows - it is not so easy to write dependency to install on windows. 由于Windows上的安装后问题,通过deb依赖关系安装节点的想法不好-编写要在Windows上安装的依赖关系并不容易。 Instead I downloaded node binaries and I packaged node binaries to asar package.
相反,我下载了节点二进制文件,并将节点二进制文件打包为asar软件包。 I used files option to package only binaries for platform building is running on:
我使用文件选项仅打包二进制文件,以便平台正在运行:
package.json: package.json:
"build": {
"asarUnpack": [
"**/*"
],
"files": [
"!binaries",
"binaries/${os}/${arch}/node",
"src",
"*.html",
"*.js",
"*.tpl",
"*.sh",
"*.json",
"*.md",
"*.lock"
],
Thanks to asarUnpack option I unpack the asar package and I'm able to access node binary on filesystem. 由于使用了asarUnpack选项,我可以解压缩asar软件包,并且可以访问文件系统上的节点二进制文件。 Then in main process index.js I'm constructing node path this way:
然后在主流程index.js中,我以这种方式构造节点路径:
const nodePath = path.join(
process.resourcesPath,
"app.asar.unpacked",
'binaries',
platform == "win32" ? "win" : platform,
arch,
"node"
)
const productionWebpackServerStartPathArgs = [`${process.resourcesPath}/app.asar.unpacked/node_modules/webpack-dev-server/bin/webpack-dev-server.js`, '--config', `${process.resourcesPath}/app.asar.unpacked/webpack.config.js`];
let webpack_dev_server_cmd = crossSpawn(nodePath, productionWebpackServerStartPathArgs );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.