电子渲染器进程中的代码在打包后不起作用
Code in electron renderer process not working after packaging
来自 index.html 的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script src="./renderer.js"></script>
</body>
<form><input></form><div></div>
</html>
renderer.js中的代码:
var io = require('socket.io')();
var os = require('os');
var fs = require('fs');
io.listen(6000);
io.on('connection', function (socket) {
socket.on('my socketId', function (data) {
socket.emit('client connect', {
nickname: os.hostname()
});
});
});
问题:在浏览器中使用 electron .
运行 效果很好。但是用electron-packager打包后客户端没有任何反应
非常感谢您的帮助!!
我终于解决了这个问题。我正在复制应用程序以首先构建。但是 node_modules (和那些包)不存在于该目录中。复制它或 运行 npm install in build before 运行ning Electron Packager 将使它工作。
来自 index.html 的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script src="./renderer.js"></script>
</body>
<form><input></form><div></div>
</html>
renderer.js中的代码:
var io = require('socket.io')();
var os = require('os');
var fs = require('fs');
io.listen(6000);
io.on('connection', function (socket) {
socket.on('my socketId', function (data) {
socket.emit('client connect', {
nickname: os.hostname()
});
});
});
问题:在浏览器中使用 electron .
运行 效果很好。但是用electron-packager打包后客户端没有任何反应
非常感谢您的帮助!!
我终于解决了这个问题。我正在复制应用程序以首先构建。但是 node_modules (和那些包)不存在于该目录中。复制它或 运行 npm install in build before 运行ning Electron Packager 将使它工作。