Skip to content
On this page

Not Bundle

Added in: v0.13.0

During the development phase, we can exclude the cjs format of npm-pkg from bundle. Like Vite's 👉 Not Bundle. It's fast!

Note

Applies to Main process and Preload scripts.

中文

在开发阶段,我们可以排除 cjs 格式 npm 包的构建。就像 Vite 的 👉 Not Bundle. 它非常快

适用于主进程预加载脚本

js
import electron from 'vite-plugin-electron'
import { notBundle } from 'vite-plugin-electron/plugin'

export default defineConfig(({ command }) => ({
  plugins: [
    electron({
      entry: 'electron/main.ts',
      vite: {
        plugins: [
          command === 'serve' && notBundle(/* NotBundleOptions */),
        ],
      },
    }),
  ],
}))

API

notBundle(/* NotBundleOptions */)

ts
export interface NotBundleOptions {
  filter?: (id: string) => void | false
}

How to work

Let's use the electron-log as an examples.

js
┏—————————————————————————————————————┓
import log from 'electron-log'
┗—————————————————————————————————————┛

Modules in `node_modules` are not bundled during development, it's fast!

┏—————————————————————————————————————┓
const log = require('electron-log') │
┗—————————————————————————————————————┛

🚧

Not Bundle will cause the code built by vite serve and vite build to be different, You must be aware of this risk!

中文

🚧 Not Bundle 会导致 vite servevite builde 构建的代码不一致,你要知道这个风险!