chore: comments

This commit is contained in:
草鞋没号 2022-05-20 07:53:50 +08:00
parent fc055bc1e9
commit 9a357d858a
1 changed files with 27 additions and 7 deletions

View File

@ -3,7 +3,7 @@ import { builtinModules } from 'module'
import { defineConfig, Plugin } from 'vite' import { defineConfig, Plugin } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import optimizer from 'vite-plugin-optimizer' import optimizer from 'vite-plugin-optimizer'
import resolve from 'vite-plugin-resolve' import resolve, { lib2esm } from 'vite-plugin-resolve'
import pkg from '../../package.json' import pkg from '../../package.json'
/** /**
@ -17,18 +17,38 @@ export default defineConfig({
electron(), electron(),
resolve({ resolve({
/** /**
* Here you resolve some CommonJs module. * Here you can resolve some CommonJs module.
* Or some Node.js native modules they may not be built correctly by vite. * Or some Node.js native modules they may not be built correctly by vite.
* At the same time, these modules should be put in `dependencies`, * At the same time, these modules should be put in `dependencies`,
* because they will not be built by vite, but will be packaged into `app.asar` by electron-builder * because they will not be built by vite, but will be packaged into `app.asar` by electron-builder
*/ */
// ESM format code snippets // ESM format code snippets
'electron-store': 'export default require("electron-store");', 'electron-store': 'export default require("electron-store");',
// Node.js native module /**
serialport: ` * Node.js native module
const { SerialPort } = require("serialport"); * Use lib2esm() to easy to convert ESM
export { SerialPort } * Equivalent to
`, *
* ```js
* 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' },
),
}), }),
], ],
base: './', base: './',