Skip to content

Commit 5e0cf0b

Browse files
authored
Merge pull request #132 from electron-vite/dev
feat: sqlite3, serialport use-cases
2 parents b2d2ce9 + 09d531f commit 5e0cf0b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

packages/renderer/vite.config.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
3-
import resolve from 'vite-plugin-resolve'
3+
import resolve, { lib2esm } from 'vite-plugin-resolve'
44
import electron from 'vite-plugin-electron/renderer'
55
import pkg from '../../package.json'
66

@@ -18,8 +18,31 @@ export default defineConfig({
1818
* which will ensure that the electron-builder can package it correctly
1919
*/
2020
{
21-
// If you use electron-store, this will work - ESM format code snippets
22-
'electron-store': 'const Store = require("electron-store"); export default Store;',
21+
// If you use the following modules, the following configuration will work
22+
// What they have in common is that they will return - ESM format code snippets
23+
24+
// ESM format string
25+
'electron-store': 'export default require("electron-store");',
26+
// Use lib2esm() to easy to convert ESM
27+
// Equivalent to
28+
/**
29+
* sqlite3: () => `
30+
* const _M_ = require('sqlite3');
31+
* const _D_ = _M_.default || _M_;
32+
* export { _D_ as default }
33+
* `
34+
*/
35+
sqlite3: lib2esm('sqlite3', { format: 'cjs' }),
36+
serialport: lib2esm(
37+
// CJS lib name
38+
'serialport',
39+
// export memebers
40+
[
41+
'SerialPort',
42+
'SerialPortMock',
43+
],
44+
{ format: 'cjs' },
45+
),
2346
}
2447
),
2548
],

0 commit comments

Comments
 (0)