Skip to content

从 v4 迁移

总体变化

废弃 externalizeDepsPlugin

externalizeDepsPlugin 已被废弃。在 v5 中,你可以通过 build.externalizeDeps 来自定义相关行为。该功能已默认启用,因此不再需要手动引入此插件。

electron.vite.config.ts
js
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { defineConfig } from 'electron-vite'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()] 
  },
  preload: {
    plugins: [externalizeDepsPlugin()] 
  }
  // ...
})

废弃 bytecodePlugin

bytecodePlugin 已被废弃。在 v5 中,你可以通过 build.bytecode 来启用或自定义此功能。

electron.vite.config.ts
js
import { defineConfig, bytecodePlugin } from 'electron-vite'
import { defineConfig } from 'electron-vite'

export default defineConfig({
  main: {
    plugins: [bytecodePlugin()] 
    build: { 
      bytecode: true
    } 
  },
  preload: {
    plugins: [bytecodePlugin()] 
    build: { 
      bytecode: true
    } 
  },
  // ...
})
electron.vite.config.ts
js
import { defineConfig, bytecodePlugin } from 'electron-vite'
import { defineConfig } from 'electron-vite'

export default defineConfig({
  main: {
    plugins: [bytecodePlugin({ protectedStrings: ['foo'] })] 
    build: { 
      bytecode: { protectedStrings: ['foo'] } 
    } 
  },
  // ...
})

配置变化

移除嵌套配置字段的函数解析

在 v5 中,不再支持mainpreloadrenderer 配置字段中使用函数式配置。你应当直接定义静态的配置对象。

js
import { defineConfig, defineViteConfig } from 'electron-vite'

export default defineConfig({
  main: {
    // ...
  },
  preload: {
    // ...
  },
  renderer: defineViteConfig(({ command, mode }) => { ❌ 
    // ...
  })
})

Released under the MIT License