Merge pull request #132 from electron-vite/dev

feat: sqlite3, serialport use-cases
This commit is contained in:
younglei 2022-05-17 17:33:42 +08:00 committed by GitHub
commit 5e0cf0bd4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import resolve from 'vite-plugin-resolve' import resolve, { lib2esm } from 'vite-plugin-resolve'
import electron from 'vite-plugin-electron/renderer' import electron from 'vite-plugin-electron/renderer'
import pkg from '../../package.json' import pkg from '../../package.json'
@ -18,8 +18,31 @@ export default defineConfig({
* which will ensure that the electron-builder can package it correctly * which will ensure that the electron-builder can package it correctly
*/ */
{ {
// If you use electron-store, this will work - ESM format code snippets // If you use the following modules, the following configuration will work
'electron-store': 'const Store = require("electron-store"); export default Store;', // What they have in common is that they will return - ESM format code snippets
// ESM format string
'electron-store': 'export default require("electron-store");',
// Use lib2esm() to easy to convert ESM
// Equivalent to
/**
* sqlite3: () => `
* const _M_ = require('sqlite3');
* const _D_ = _M_.default || _M_;
* export { _D_ as default }
* `
*/
sqlite3: lib2esm('sqlite3', { format: 'cjs' }),
serialport: lib2esm(
// CJS lib name
'serialport',
// export memebers
[
'SerialPort',
'SerialPortMock',
],
{ format: 'cjs' },
),
} }
), ),
], ],