vue3 electron 打包后进程通信无效,开发环境正常

vue3 electron 打包后进程通信无效,开发环境却正常。
出现这个问题,是因为vue.config.js文件中electronBuilder项没有添加preload属性导致的,解决方式如下:

vue.config.js文件

const { defineConfig } = require("@vue/cli-service");
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    resolve: { fallback: { fs: false, path: false } },
  },
  pluginOptions: {
    electronBuilder: {
      //打包配置
      preload: "src/preload.js", //根据项目中的preload.js路径,添加此行就可以了
      builderOptions: {
        productName: "xxx",
        appId: "xxx",
        copyright: "xxx",
        directories: {
          output: "dist_electron",
        },
        nsis: {
          oneClick: false,
          allowElevation: false,
          allowToChangeInstallationDirectory: true,
          installerIcon: "public/favicon.ico",
          uninstallerIcon: "public/favicon.ico",
          installerHeaderIcon: "public/favicon.ico",
          createDesktopShortcut: true,
          createStartMenuShortcut: true,
          shortcutName: "xxx",
          runAfterFinish: false,
        },
        mac: {
          icon: "public/favicon.ico",
        },
        win: {
          icon: "public/favicon.ico",
        },
      },
    },
  },
});

你可能感兴趣的:(技术开发,electron,Vue.js,electron,vue.js,javascript)