一个基于 Webpack 的预构建(pre-bundle) 方案, 主要用于适配 Node.js 和 Electron。
English | 简体中文
npm i -D vite-plugin-webpack-prebundleimport prebundle from 'vite-plugin-webpack-prebundle'
export default {
plugins: [
prebundle({
modules: [
'foo',
'bar',
],
})
]
}export interface PrebundleOptions {
/** An array of module names that need to be pre-bundle. */
modules: string[]
config?: (config: Configuration) => Configuration | undefined | Promise<Configuration | undefined>
}这是一个专为 Node/Electron 应用而生的 Pre-Bundling 方案,与 Vite 内置的 Dependency Pre-Bundling 行为一致。使用 Webpack 的原因是对于 Node/Electron 应用来说,它是目前兼容性最好的 Bundler。
| Pre-Bundle solution | Web | Node/Electron |
|---|---|---|
| Vite 内置的 Dependency Pre-Bundling | ✅ | ❌ |
| vite-plugin-webpack-prebundle | ✅ | ✅ |