docs: Use SerialPort, SQLite3 or other node-native addons in Main-process

This commit is contained in:
草鞋没号 2022-01-27 16:00:07 +08:00
parent 76c4b446b6
commit 453f7e3be0

View File

@ -95,6 +95,33 @@ Once `dev` or `build` npm-script executed will be generate named `dist` folder.
console.log('ipcRenderer', window.ipcRenderer)
```
## Use SerialPort, SQLite3 or other node-native addons in Main-process
Main-process, Preload-script are also built with Vite, and they are just built as [build.lib](https://vitejs.dev/config/#build-lib).
So they just need to configure Rollup.
**Click to view more** 👉 [scripts/vite.config.mjs](https://github.com/caoxiemeihao/electron-vue-vite/blob/main/scripts/vite.config.mjs)
```js
export default {
build: {
// built lib for Main-process, Preload-script
lib: {
entry: 'index.ts',
formats: ['cjs'],
fileName: () => '[name].js',
},
rollupOptions: {
// configuration here
external: [
'serialport',
'sqlite3',
],
},
},
}
```
## `dependencies` vs `devDependencies`
- First, you need to know if deps(npm package) are still needed after packaged.