electron build 打包时,背景图片失败,background-image: url 被转换成app:///img/

F12 console 报错:Failed to load resource: net::ERR_FAILED
这是因为 electron build 时,background-image: url(‘’) 被转换成 app:///img/ …
参考:

https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/configuration.html#changing-the-file-loading-protocol

通过在vue.config.js中添加customFileProtocol,再次打包成功!

const { defineConfig } = require("@vue/cli-service");
module.exports = defineConfig({
  transpileDependencies: ["vuetify"],
  pluginOptions: {
    electronBuilder: {
      customFileProtocol: "./",
    },
  },
});

你可能感兴趣的:(electron,vue.js,javascript,build,background)