Skip to content
索引

插件的用法

1.使用vite脚手架新建一个项目,安装electron、vite-plugin-electron

sh
npm create vite electron-vite-app
cd electron-vite-app
npm i -s electron
npm i -D vite-plugin-electron
npm create vite electron-vite-app
cd electron-vite-app
npm i -s electron
npm i -D vite-plugin-electron

2.项目根目录新建electron/main.ts

TS
import { app, BrowserWindow } from "electron";
app.whenReady().then(()=>{
  new BrowserWindow().loadURL("http://localhost:3000")
})
import { app, BrowserWindow } from "electron";
app.whenReady().then(()=>{
  new BrowserWindow().loadURL("http://localhost:3000")
})

3.vite.config.ts中使用插件

js
import electron from 'vite-plugin-electron'

export default {
  plugins: [
    electron({
      entry: 'electron/main.ts',
    }),
  ],
}
import electron from 'vite-plugin-electron'

export default {
  plugins: [
    electron({
      entry: 'electron/main.ts',
    }),
  ],
}

4.package.json中添加main字段

ts
"main": "dist-electron/main.js",
"main": "dist-electron/main.js",

Released under the MIT License.