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.
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 serve
与 vite builde
构建的代码不一致,你要知道这个风险!