Skip to content

Commit

Permalink
Merge pull request #58 from electron-vite/v0.14.0
Browse files Browse the repository at this point in the history
V0.14.0
  • Loading branch information
caoxiemeihao authored Apr 13, 2023
2 parents 551f966 + 271e291 commit 0e08cd6
Show file tree
Hide file tree
Showing 11 changed files with 870 additions and 775 deletions.
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## 0.14.0 (2023-04-13)

#### Break!

```diff
export interface RendererOptions {
resolve?: {
- [id: string]: (() => string | { platform: 'browser' | 'node' } | Promise<string | { platform: 'browser' | 'node' }>)
+ [module: string]: {
+ type: 'cjs' | 'esm',
+ build?: (args: {
+ cjs: (module: string) => Promise<string>,
+ esm: (module: string, buildOptions?: import('esbuild').BuildOptions) => Promise<string>,
+ }) => Promise<string>
+ }
}
}
```

#### Main Changed

1. on-demand pre-bundle builtin, third-part C/C++, `esm` modules
2. support full custom pre-bundle

- 98c4d27 docs: v0.14.0
- af6bb2b chore(examples): update quick-start
- 110c854 chore: better build script
- cd1b5bb chore: remove `.npmrc`
- b8038f5 refactor(v0.14.0): better `options.resolve`
- 7c5afae refactor(v0.14.0): on-demand pre-bundle

## 0.13.14 (2023-03-31)

- 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)
Expand Down
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
}
```

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

```js
import renderer from 'vite-plugin-electron-renderer'
Expand All @@ -55,7 +55,10 @@ export default {
plugins: [
renderer({
resolve: {
serialport: () => ({ platform: 'node' }), // specify as `node` platform
// C/C++ modules must be pre-bundle
serialport: { type: 'cjs' },
// `esm` modules only if Vite does not pre-bundle them correctly
got: { type: 'esm' },
},
}),
],
Expand All @@ -69,26 +72,22 @@ export default {
```ts
export interface RendererOptions {
/**
* Explicitly tell Vite how to load modules, which is very useful for C/C++ modules.
* 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' }`.
* Explicitly tell Vite how to load modules, which is very useful for C/C++ and `esm` modules
*
* If you know exactly how Vite works, you can customize the return snippets.
*
* ```js
* renderer({
* resolve: {
* // Use the serialport(C/C++) module as an example
* serialport: () => ({ platform: 'node' }),
* // Equivalent to
* serialport: () => `const lib = require("serialport"); export default lib.default || lib;`,
* },
* })
* ```
* - `type.cjs` just wraps esm-interop
* - `type.esm` pre-bundle to `cjs` and wraps esm-interop
*
* @experimental
*/
resolve?: {
[id: string]: (() => string | { platform: 'browser' | 'node' } | Promise<string | { platform: 'browser' | 'node' }>)
[module: string]: {
type: 'cjs' | 'esm',
/** Full custom how to pre-bundle */
build?: (args: {
cjs: (module: string) => Promise<string>,
esm: (module: string, buildOptions?: import('esbuild').BuildOptions) => Promise<string>,
}) => Promise<string>
}
}
}
```
Expand Down
2 changes: 0 additions & 2 deletions examples/quick-start/.npmrc

This file was deleted.

4 changes: 0 additions & 4 deletions examples/quick-start/renderer/samples/node.js-api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { ipcRenderer } from 'electron'
import fs from 'fs/promises'
import buffer from 'buffer'

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

console.log('----', buffer.hasOwnProperty('aaa'), '----')

3 changes: 2 additions & 1 deletion examples/quick-start/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default defineConfig({
}),
renderer({
resolve: {
serialport: () => ({ platform: 'node' }),
serialport: { type: 'cjs' },
got: { type: 'esm' },
},
}),
],
Expand Down
93 changes: 0 additions & 93 deletions install.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-electron-renderer",
"version": "0.13.14",
"version": "0.14.0",
"description": "Support use Node.js API in Electron-Renderer",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -23,7 +23,6 @@
"build": "vite build",
"types": "tsc --emitDeclarationOnly",
"prepublishOnly": "npm run test && npm run build",
"postinstall": "node install.js",
"test": "vitest run"
},
"dependencies": {
Expand All @@ -34,6 +33,7 @@
"rollup": "^3.19.1",
"typescript": "^5.0.2",
"vite": "^4.2.0",
"vite-plugin-utils": "^0.4.0",
"vitest": "^0.29.3"
},
"files": [
Expand Down
Loading

0 comments on commit 0e08cd6

Please sign in to comment.