前言
我用vue cli 4.0创建了一个简单的vue app,并成功地将其与electron集成。一切都运行得很好,直到我尝试在vue文件中导入electron。问题是我不能通过ipcRenderer向主进程发送消息。
Uncaught TypeError: fs.existsSync is not a function
at getElectronPath (index.js?1704:7)
at eval (index.js?1704:18)
at Object../node_modules/_electron@11.0.0@electron/index.js (chunk-vendors.js:10)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/AppTitle/TitleBtn.vue?vue&type=script&lang=js&:2)
at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/AppTitle/TitleBtn.vue?vue&type=script&lang=js& (app.js:1031)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
解决方法
在 vue.config.js 中添加
nodeIntegration: true