Skip to content

Commit 8e0fe47

Browse files
authored
Merge pull request #9 from electron-vite/v0.10.4
V0.10.4
2 parents ee4b079 + d0761a6 commit 8e0fe47

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.10.4 (2022-11-14)
2+
3+
`optimizerDeps` should not process builtins, builtins will be processed in `use-node.js.ts`.
4+
5+
- 6436b49 fix: avoid built-in modules
6+
17
## 0.10.3 (2022-11-09)
28

39
- `optimizerDeps` generate sourcemap by default vite-plugin-electron#70

examples/quick-start/electron/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ app.whenReady().then(() => {
1515
},
1616
})
1717

18-
if (app.isPackaged) {
19-
win.loadFile(path.join(__dirname, '../dist/index.html'))
20-
} else {
18+
if (process.env.VITE_DEV_SERVER_URL) {
2119
win.loadURL(process.env.VITE_DEV_SERVER_URL)
2220
win.webContents.openDevTools()
21+
} else {
22+
win.loadFile(path.join(__dirname, '../dist/index.html'))
2323
}
2424
})
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import './samples'
22

33
document.getElementById('app')!.innerHTML = `
4-
<h1>examples/nodeIntegration</h1>
4+
<h1>Hi there 👋</h1>
5+
<p>Now, you can use Electron and Node.js API in Renderer process.</p>
6+
<pre>
7+
import { ipcRenderer } from 'electron'
8+
import fs from 'fs'
9+
</pre>
510
`

examples/worker/electron/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ app.whenReady().then(() => {
1414
nodeIntegrationInWorker: true,
1515
}
1616
})
17-
if (app.isPackaged) {
18-
win.loadFile(path.join(__dirname, '../dist/index.html'))
19-
} else {
17+
if (process.env.VITE_DEV_SERVER_URL) {
2018
win.loadURL(process.env.VITE_DEV_SERVER_URL)
2119
win.webContents.openDevTools()
20+
} else {
21+
win.loadFile(path.join(__dirname, '../dist/index.html'))
2222
}
2323

2424
const worker = new Worker(path.join(__dirname, './worker.js'))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-electron-renderer",
3-
"version": "0.10.3",
3+
"version": "0.10.4",
44
"description": "Support use Node.js API in Electron-Renderer",
55
"main": "plugins/index.mjs",
66
"types": "plugins",

src/optimizer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ export type DepOptimizationConfig = {
1919
}
2020

2121
const cjs_require = createRequire(import.meta.url)
22+
const builtins = [
23+
...builtinModules,
24+
...builtinModules.map(mod => `node:${mod}`),
25+
]
26+
const CACHE_DIR = '.vite-electron-renderer'
27+
2228
let root: string
2329
let node_modules_path: string
24-
const CACHE_DIR = '.vite-electron-renderer'
2530

2631
export default function optimizer(options: DepOptimizationConfig): Plugin {
2732
return {
@@ -61,6 +66,10 @@ export default function optimizer(options: DepOptimizationConfig): Plugin {
6166
deps.push({ cjs: name })
6267
continue
6368
}
69+
if (builtins.includes(name)) {
70+
// Process in './use-node.js.ts'
71+
continue
72+
}
6473
const pkg = cjs_require(path.join(node_modules_path, name, 'package.json'))
6574
if (pkg) {
6675
// bare module

0 commit comments

Comments
 (0)