Skip to content

Commit 0e08cd6

Browse files
authored
Merge pull request #58 from electron-vite/v0.14.0
V0.14.0
2 parents 551f966 + 271e291 commit 0e08cd6

File tree

11 files changed

+870
-775
lines changed

11 files changed

+870
-775
lines changed

.npmrc

Lines changed: 0 additions & 2 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
## 0.14.0 (2023-04-13)
2+
3+
#### Break!
4+
5+
```diff
6+
export interface RendererOptions {
7+
resolve?: {
8+
- [id: string]: (() => string | { platform: 'browser' | 'node' } | Promise<string | { platform: 'browser' | 'node' }>)
9+
+ [module: string]: {
10+
+ type: 'cjs' | 'esm',
11+
+ build?: (args: {
12+
+ cjs: (module: string) => Promise<string>,
13+
+ esm: (module: string, buildOptions?: import('esbuild').BuildOptions) => Promise<string>,
14+
+ }) => Promise<string>
15+
+ }
16+
}
17+
}
18+
```
19+
20+
#### Main Changed
21+
22+
1. on-demand pre-bundle builtin, third-part C/C++, `esm` modules
23+
2. support full custom pre-bundle
24+
25+
- 98c4d27 docs: v0.14.0
26+
- af6bb2b chore(examples): update quick-start
27+
- 110c854 chore: better build script
28+
- cd1b5bb chore: remove `.npmrc`
29+
- b8038f5 refactor(v0.14.0): better `options.resolve`
30+
- 7c5afae refactor(v0.14.0): on-demand pre-bundle
31+
132
## 0.13.14 (2023-03-31)
233

334
- c68d26a fix: move cjs config to cjs-shim.ts #107 | [electron-vite-vue/issues/107](https://github.com/electron-vite/electron-vite-vue/issues/107)

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
}
4747
```
4848

49-
2. Using the third-part C/C++ package in the Renderer process.
49+
2. Using the third-part C/C++, `esm` package in the Renderer process.
5050

5151
```js
5252
import renderer from 'vite-plugin-electron-renderer'
@@ -55,7 +55,10 @@ export default {
5555
plugins: [
5656
renderer({
5757
resolve: {
58-
serialport: () => ({ platform: 'node' }), // specify as `node` platform
58+
// C/C++ modules must be pre-bundle
59+
serialport: { type: 'cjs' },
60+
// `esm` modules only if Vite does not pre-bundle them correctly
61+
got: { type: 'esm' },
5962
},
6063
}),
6164
],
@@ -69,26 +72,22 @@ export default {
6972
```ts
7073
export interface RendererOptions {
7174
/**
72-
* Explicitly tell Vite how to load modules, which is very useful for C/C++ modules.
73-
* Most of the time, you don't need to use it when a module is a C/C++ module, you can load them by return `{ platform: 'node' }`.
75+
* Explicitly tell Vite how to load modules, which is very useful for C/C++ and `esm` modules
7476
*
75-
* If you know exactly how Vite works, you can customize the return snippets.
76-
*
77-
* ```js
78-
* renderer({
79-
* resolve: {
80-
* // Use the serialport(C/C++) module as an example
81-
* serialport: () => ({ platform: 'node' }),
82-
* // Equivalent to
83-
* serialport: () => `const lib = require("serialport"); export default lib.default || lib;`,
84-
* },
85-
* })
86-
* ```
77+
* - `type.cjs` just wraps esm-interop
78+
* - `type.esm` pre-bundle to `cjs` and wraps esm-interop
8779
*
8880
* @experimental
8981
*/
9082
resolve?: {
91-
[id: string]: (() => string | { platform: 'browser' | 'node' } | Promise<string | { platform: 'browser' | 'node' }>)
83+
[module: string]: {
84+
type: 'cjs' | 'esm',
85+
/** Full custom how to pre-bundle */
86+
build?: (args: {
87+
cjs: (module: string) => Promise<string>,
88+
esm: (module: string, buildOptions?: import('esbuild').BuildOptions) => Promise<string>,
89+
}) => Promise<string>
90+
}
9291
}
9392
}
9493
```

examples/quick-start/.npmrc

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { ipcRenderer } from 'electron'
22
import fs from 'fs/promises'
3-
import buffer from 'buffer'
43

54
console.log('Electron API:\n', ipcRenderer)
65
console.log('Node.js API(fs/promises):\n', fs)
7-
8-
console.log('----', buffer.hasOwnProperty('aaa'), '----')
9-

examples/quick-start/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export default defineConfig({
99
}),
1010
renderer({
1111
resolve: {
12-
serialport: () => ({ platform: 'node' }),
12+
serialport: { type: 'cjs' },
13+
got: { type: 'esm' },
1314
},
1415
}),
1516
],

install.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-electron-renderer",
3-
"version": "0.13.14",
3+
"version": "0.14.0",
44
"description": "Support use Node.js API in Electron-Renderer",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -23,7 +23,6 @@
2323
"build": "vite build",
2424
"types": "tsc --emitDeclarationOnly",
2525
"prepublishOnly": "npm run test && npm run build",
26-
"postinstall": "node install.js",
2726
"test": "vitest run"
2827
},
2928
"dependencies": {
@@ -34,6 +33,7 @@
3433
"rollup": "^3.19.1",
3534
"typescript": "^5.0.2",
3635
"vite": "^4.2.0",
36+
"vite-plugin-utils": "^0.4.0",
3737
"vitest": "^0.29.3"
3838
},
3939
"files": [

0 commit comments

Comments
 (0)