Skip to content

Commit

Permalink
Merge pull request #140 from electron-vite/v0.12.0
Browse files Browse the repository at this point in the history
V0.12.0
  • Loading branch information
caoxiemeihao authored Jun 13, 2023
2 parents d3bd7c6 + 98ae6e2 commit 4fa940d
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 78 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.12.0 (2022-06-13)

- 6822409 docs: v0.12.0
- 9ec9d3b v0.12.0
- 53a0dd8 feat: disable minify during dev
- 3925cd1 refactor: remove `defineConfig`, `Configuration` -> `ElectronOptions`, config.ts -> utils.ts

## 0.11.2 (2022-04-15)

- b033bc5 v0.11.2
Expand Down
74 changes: 54 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- 🐣 Few APIs, easy to use
- 🔥 Hot restart

![vite-plugin-electron.gif](https://github.com/caoxiemeihao/blog/blob/main/vite/vite-plugin-electron.gif?raw=true)
<!-- ![vite-plugin-electron.gif](https://github.com/electron-vite/vite-plugin-electron/blob/main/vite-plugin-electron.gif?raw=true) -->

## Quick Setup

Expand Down Expand Up @@ -89,10 +89,10 @@ That's it! You can now use Electron in your Vite app ✨

## API <sub><sup>(Define)</sup></sub>

`electron(config: Configuration | Configuration[])`
`electron(config: ElectronOptions | ElectronOptions[])`

```ts
export interface Configuration {
export interface ElectronOptions {
/**
* Shortcut of `build.lib.entry`
*/
Expand Down Expand Up @@ -150,8 +150,7 @@ Let's use the official [template-vanilla-ts](https://github.com/vitejs/vite/tree

`vite-plugin-electron`'s JavaScript APIs are fully typed, and it's recommended to use TypeScript or enable JS type checking in VS Code to leverage the intellisense and validation.

- `Configuration` - type
- `defineConfig` - function
- `ElectronOptions` - type
- `resolveViteConfig` - function, Resolve the default Vite's `InlineConfig` for build Electron-Main
- `withExternalBuiltins` - function
- `build` - function
Expand Down Expand Up @@ -194,22 +193,57 @@ It just executes the `electron .` command in the Vite build completion hook and

- 🚨 By default, the files in `electron` folder will be built into the `dist-electron`
- 🚨 Currently, `"type": "module"` is not supported in Electron
- 🚨 In general, Vite may not correctly build Node.js packages, especially C/C++ native modules, but Vite can load them as external packages. So, put your Node.js package in `dependencies`. Unless you know how to properly build them with Vite.
```js
electron({
entry: 'electron/main.ts',
vite: {
build: {
rollupOptions: {
// Here are some C/C++ modules them can't be built properly.
external: [
'serialport',
'sqlite3',
],

## C/C++ Native

We have two ways to use C/C++ native modules

**First**

In general, Vite may not correctly build Node.js packages, especially C/C++ native modules, but Vite can load them as external packages

So, put your Node.js package in `dependencies`. Unless you know how to properly build them with Vite

```js
export default {
plugins: [
electron({
entry: 'electron/main.ts',
vite: {
build: {
rollupOptions: {
// Here are some C/C++ modules them can't be built properly
external: [
'serialport',
'sqlite3',
],
},
},
},
},
}),
```
}),
],
}
```

**Second**

Use 👉 [vite-plugin-native](https://github.com/vite-plugin/vite-plugin-native)

```js
import native from 'vite-plugin-native'

export default {
plugins: [
electron({
entry: 'electron/main.ts',
vite: {
plugins: [
native(/* options */),
],
},
}),
],
}
```

<!-- You can see 👉 [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies) -->
33 changes: 33 additions & 0 deletions logo.animate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions logo.v1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-electron",
"version": "0.11.2",
"version": "0.12.0",
"description": "Electron 🔗 Vite",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
Loading

0 comments on commit 4fa940d

Please sign in to comment.