Skip to content

Commit e03eef2

Browse files
authored
Merge pull request #12 from electron-vite/v0.11.2
V0.11.2
2 parents f34fab7 + 782e01c commit e03eef2

File tree

12 files changed

+67
-54
lines changed

12 files changed

+67
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ package-lock.json
110110
yarn.lock
111111

112112
/types
113+
/builtins
113114
/index.mjs
114115
/index.cjs
115116
/index.js

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
## 0.11.2 (2022-11-18)
2+
3+
1. Pre-Bundling Node.js built-in modules by default.
4+
2. Fixed incorrect loading of static resources *(It does not support custom assetsDir)*.
5+
6+
- ee51908 feat: build built-in modules 🌱
7+
- 51d5287 fix: `assetsDir` default value
8+
- 5d0dfc0 refactor: always Pre-Bundling built-in modules
9+
110
## 0.11.1 (2022-11-16)
211

3-
- a8c546b fix: add 'vite-plugin-electron-renderer/electron-renderer' to `optimizeDeps.exclude`
12+
- a8c546b fix: add 'vite-plugin-electron-renderer/electron-renderer' to `optimizeDeps.exclude`.
413

514
## 0.11.0 (2022-11-15)
615

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ipcRenderer } from 'electron'
2-
import fs from 'fs'
2+
import fs from 'fs/promises'
33

44
console.log('Electron API:\n', ipcRenderer)
5-
console.log('Node.js API:\n', fs)
5+
console.log('Node.js API(fs/promises):\n', fs)

examples/quick-start/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default defineConfig({
1414
// Like Vite's pre bundling
1515
optimizeDeps: {
1616
include: [
17-
'fs', // built-in
1817
'serialport', // cjs(C++)
1918
'electron-store', // cjs
2019
'execa', // esm

examples/worker/renderer/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import fs from 'fs'
2-
31
document.getElementById('app')!.innerHTML = `
42
<h1>examples/web-worker</h1>
53
<button id="worker">Click to load Web Worker</button>
64
`
75
document.getElementById('worker')!.addEventListener('click', () => {
86
new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' })
97
})
10-
11-
console.log(fs)

examples/worker/renderer/worker.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { join } from 'path'
2-
import path from 'path'
3-
import fs from 'fs'
2+
import fs from 'node:fs/promises'
43

5-
console.log(join('a', 'b'))
6-
console.log(path.join('c', 'd'))
7-
console.log(fs)
4+
console.log("join('a', 'b') ->", join('a', 'b'))
5+
console.log('node:fs/promises ->', fs)

examples/worker/vite.config.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ export default defineConfig({
1616
}),
1717
renderer({
1818
nodeIntegration: true,
19-
optimizeDeps: {
20-
include: [
21-
'fs',
22-
'path',
23-
]
24-
},
2519
}),
2620
],
2721
})

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-electron-renderer",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"description": "Support use Node.js API in Electron-Renderer",
55
"main": "index.mjs",
66
"types": "types",
@@ -9,7 +9,7 @@
99
"import": "./index.mjs",
1010
"require": "./index.js"
1111
},
12-
"./electron-renderer": "./electron-renderer.js"
12+
"./*": "./*"
1313
},
1414
"repository": {
1515
"type": "git",
@@ -38,7 +38,8 @@
3838
"types",
3939
"index.mjs",
4040
"index.js",
41-
"electron-renderer.js"
41+
"electron-renderer.js",
42+
"builtins"
4243
],
4344
"keywords": [
4445
"vite",

src/build-config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import type { ExternalOption, RollupOptions } from 'rollup'
44

55
export const builtins = [
66
'electron',
7-
...builtinModules,
8-
...builtinModules.map(mod => `node:${mod}`),
7+
...builtinModules.filter(m => !m.startsWith('_')),
8+
...builtinModules.filter(m => !m.startsWith('_')).map(mod => `node:${mod}`),
99
]
1010

1111
export default function buildConfig(nodeIntegration?: boolean): Plugin {
1212
return {
1313
name: 'vite-plugin-electron-renderer:build-config',
1414
apply: 'build',
1515
config(config) {
16-
// make sure that Electron can be loaded into the local file using `loadFile` after packaging
16+
// Make sure that Electron can be loaded into the local file using `loadFile` after packaging
1717
config.base ??= './'
1818

1919
config.build ??= {}
@@ -24,6 +24,11 @@ export default function buildConfig(nodeIntegration?: boolean): Plugin {
2424
// https://github.com/electron-vite/electron-vite-vue/issues/107
2525
config.build.cssCodeSplit ??= false
2626

27+
// TODO: compatible with custom assetsDir
28+
// This will guarantee the proper loading of static resources, such as images, `worker.js`
29+
// The `.js` file can be loaded correctly with cjs-shim.ts
30+
config.build.assetsDir ??= ''
31+
2732
if (nodeIntegration) {
2833
config.build.rollupOptions ??= {}
2934
config.build.rollupOptions.external = withExternal(config.build.rollupOptions.external)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function renderer(
1818
): PluginOption {
1919
return [
2020
buildConfig(options.nodeIntegration),
21+
optimizer(options.optimizeDeps),
2122
options.nodeIntegration && cjsShim(),
22-
options.optimizeDeps && optimizer(options.optimizeDeps),
2323
]
2424
}

0 commit comments

Comments
 (0)