Skip to content

Commit

Permalink
feat: support esmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Apr 18, 2024
1 parent e2c3822 commit 9c84030
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { app, BrowserWindow } from 'electron'
import { fileURLToPath } from 'node:url'
import path from 'node:path'

globalThis.__filename = fileURLToPath(import.meta.url)
globalThis.__dirname = path.dirname(__filename)

// The built directory structure
//
// ├─┬─┬ dist
// │ │ └── index.html
// │ │
// │ ├─┬ dist-electron
// │ │ ├── main.js
// │ │ └── preload.js
// │ │ └── preload.mjs
// │
process.env.APP_ROOT = path.join(__dirname, '..')

Expand All @@ -25,7 +29,7 @@ function createWindow() {
win = new BrowserWindow({
icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'),
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
preload: path.join(__dirname, 'preload.mjs'),
},
})

Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ function setupElectron(root: string, framework: Framework) {
editFile(path.join(root, 'package.json'), content => {
const json = JSON.parse(content)
json.main = 'dist-electron/main.js'
json.type = undefined // Electron(24-) only support CommonJs now
json.scripts.build = `${json.scripts.build} && electron-builder`
json.devDependencies.electron = pkg.devDependencies.electron
json.devDependencies['electron-builder'] = pkg.devDependencies['electron-builder']
Expand Down

0 comments on commit 9c84030

Please sign in to comment.