perf: no need to polyfill module preload for the Electron renderer

This commit is contained in:
alex8088 2022-03-28 11:52:42 +08:00
parent ef99b02b18
commit 82477b6db2
3 changed files with 7 additions and 5 deletions

View file

@ -73,10 +73,10 @@ function createWindow() {
| ├──preload | ├──preload
| | ├──index.js | | ├──index.js
| | └──... | | └──...
| ──renderer | ──renderer
| | ├──src | ├──src
| | ├──index.html | ├──index.html
| | └──... | └──...
├──electron.vite.config.js ├──electron.vite.config.js
└──package.json └──package.json
``` ```
@ -178,6 +178,7 @@ See [vitejs.dev](https://vitejs.dev/config)
- **outDir**: `out\renderer`(relative to project root) - **outDir**: `out\renderer`(relative to project root)
- **target**: `chrome*`, automatically match chrome target of `Electron`. For example, the chrome target of Electron 17 is `chrome98` - **target**: `chrome*`, automatically match chrome target of `Electron`. For example, the chrome target of Electron 17 is `chrome98`
- **lib.entry**: `src\renderer\index.html`(relative to project root), empty string if not found - **lib.entry**: `src\renderer\index.html`(relative to project root), empty string if not found
- **polyfillModulePreload**: `false`, there is no need to polyfill `Module Preload` for the Electron renderer
- **rollupOptions.external**: the same as `main` - **rollupOptions.external**: the same as `main`
#### Define option for `main` and `preload` #### Define option for `main` and `preload`

View file

@ -1,6 +1,6 @@
{ {
"name": "electron-vite", "name": "electron-vite",
"version": "1.0.0", "version": "1.0.1",
"description": "Use vite for your electron app.", "description": "Use vite for your electron app.",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View file

@ -226,6 +226,7 @@ export function electronRendererVitePlugin(options?: ElectronPluginOptions): Plu
build: { build: {
outDir: path.resolve(root, 'out', 'renderer'), outDir: path.resolve(root, 'out', 'renderer'),
target: chromeTarget, target: chromeTarget,
polyfillModulePreload: false,
rollupOptions: { rollupOptions: {
input: findInput(root), input: findInput(root),
external: [...builtinModules.flatMap(m => [m, `node:${m}`])] external: [...builtinModules.flatMap(m => [m, `node:${m}`])]