不打包
新增于: v0.13.0
在开发阶段,我们可以排除 npm 包的 cjs
格式构建。就像 Vite 的 👉 不打包. 它很快!
注意
适用于主进程和预加载脚本。
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
}
工作原理
让我们以 electron-log
为例。
js
┏—————————————————————————————————————┓
│ import log from 'electron-log' │
┗—————————————————————————————————————┛
↓
Modules in `node_modules` are not bundled during development, it's fast!
↓
┏—————————————————————————————————————┓
│ const log = require('electron-log') │
┗—————————————————————————————————————┛
🚧
不打包会导致 vite serve
和 vite build
生成的代码不一致,请注意此风险!
中文
🚧 不打包会导致 vite serve
与 vite builde
构建的代码不一致,你要知道这个风险!