【问题标题】:Electron with Vue disable auto reload带有 Vue 的电子禁用自动重新加载
【发布时间】:2020-02-25 09:10:41
【问题描述】:

我使用 tutorial 安装了带有 Vue 的 Electron。

我正在寻找如何禁用自动重新加载的答案? 我使用npm run dev 启动我的应用程序,当我在代码中更改一些想法时,电子运行自动重新加载(再次刷新并编译应用程序 )。我想在编写部分代码后自己刷新应用程序。 我不使用Webpack

是的,我知道我可以在 Visual Studio Code 中禁用自动保存,但这不是解决方案。

【问题讨论】:

  • 如果您正在遵循该特定教程,那么您正在使用 Webpack,因为它引用的“simulatedgreg/electron-vue”模板使用了 Webpack:SimulatedGREG/electron-vue

标签: 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(),可以将其删除。

【讨论】:

  • @michal 没有使用 webpack
  • @tpikachu simulatedgreg/electron-vue 自动设置 webpack。如果你在教程中输入了npm run dev,那么你正在使用 webpack。
猜你喜欢
  • 2020-02-24
  • 1970-01-01
  • 2016-08-25
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 2020-02-29
相关资源
最近更新 更多