【问题标题】:Electron with Vue disable auto reload带有 Vue 的电子禁用自动重新加载
【发布时间】:2020-02-25 09:10:41
【问题描述】:
我使用 tutorial 安装了带有 Vue 的 Electron。
我正在寻找如何禁用自动重新加载的答案?
我使用npm run dev 启动我的应用程序,当我在代码中更改一些想法时,电子运行自动重新加载(再次刷新并编译应用程序
)。我想在编写部分代码后自己刷新应用程序。
我不使用Webpack。
是的,我知道我可以在 Visual Studio Code 中禁用自动保存,但这不是解决方案。
【问题讨论】:
标签:
vue.js
electron
reload
【解决方案1】:
在 Main 和 Renderer 进程上禁用
去掉dev-runner.js > startMain()中对startElectron()的调用。
function startMain () {
return new Promise((resolve, reject) => {
mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
mainConfig.mode = 'development'
const compiler = webpack(mainConfig)
compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => {
//Remove these lines and ...
// logStats('Main', chalk.white.bold('compiling...'))
// hotMiddleware.publish({ action: 'compiling' })
done()
})
compiler.watch({}, (err, stats) => {
if (err) {
console.log(err)
return
}
//... these lines.
// logStats('Main', stats)
//
// if (electronProcess && electronProcess.kill) {
// manualRestart = true
// process.kill(electronProcess.pid)
// electronProcess = null
// startElectron()
//
// setTimeout(() => {
// manualRestart = false
// }, 5000)
// }
resolve()
})
})
}
仅在渲染器进程上禁用
从src/main/index.js删除下面的导入行。
import '../renderer/store';
vuex-electron 需要这一行,这使得 vuex 可以在主进程上运行。如果您不打算使用createPersistedState() 或createSharedMutations(),可以将其删除。