Skip to content

Commit 9c84030

Browse files
committed
feat: support esmodule
1 parent e2c3822 commit 9c84030

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

electron/main.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { app, BrowserWindow } from 'electron'
2+
import { fileURLToPath } from 'node:url'
23
import path from 'node:path'
34

5+
globalThis.__filename = fileURLToPath(import.meta.url)
6+
globalThis.__dirname = path.dirname(__filename)
7+
48
// The built directory structure
59
//
610
// ├─┬─┬ dist
711
// │ │ └── index.html
812
// │ │
913
// │ ├─┬ dist-electron
1014
// │ │ ├── main.js
11-
// │ │ └── preload.js
15+
// │ │ └── preload.mjs
1216
// │
1317
process.env.APP_ROOT = path.join(__dirname, '..')
1418

@@ -25,7 +29,7 @@ function createWindow() {
2529
win = new BrowserWindow({
2630
icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'),
2731
webPreferences: {
28-
preload: path.join(__dirname, 'preload.js'),
32+
preload: path.join(__dirname, 'preload.mjs'),
2933
},
3034
})
3135

src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ function setupElectron(root: string, framework: Framework) {
262262
editFile(path.join(root, 'package.json'), content => {
263263
const json = JSON.parse(content)
264264
json.main = 'dist-electron/main.js'
265-
json.type = undefined // Electron(24-) only support CommonJs now
266265
json.scripts.build = `${json.scripts.build} && electron-builder`
267266
json.devDependencies.electron = pkg.devDependencies.electron
268267
json.devDependencies['electron-builder'] = pkg.devDependencies['electron-builder']

0 commit comments

Comments
 (0)