使用 quasar + vite 编写electron应用程序,同时用node编写的server后台,想在程序启动时自动运行后台服务。打包之后,代码都被编译,我目前没找到是否有什么办法可以像vue的 assets文件夹一样的办法,可以打包的时候原封不动的打包到根目录,所以后台代码需要打完包粘贴到根目录(也算是曲线救国)。server文件夹为后台代码,以下为打完包的项目结构。
现在来说说前台如何实现。首先需要在主线程里编辑,使用exec执行脚本。
代码如下:
// // 在Electron主进程文件中
const { exec } = require('child_process');
function runNodeScript(scriptPath) {
console.log(scriptPath, 'scriptPath');
exec('node ' + scriptPath, (error, stdout, stderr) => {
console.log('exec', error, stdout, stderr);
if (error) {
console.log(`执行出错: ${error}`);
r