format code

This commit is contained in:
草鞋没号 2022-02-08 11:25:06 +08:00
parent 2fed75baf0
commit 3ca324376e
1 changed files with 42 additions and 42 deletions

View File

@ -14,15 +14,15 @@ export default defineConfig({
plugins: [ plugins: [
react(), react(),
resolveElectron( resolveElectron(
/** /**
* Here you can specify other modules * Here you can specify other modules
* 🚧 You have to make sure that your module is in `dependencies` and not in the` devDependencies`, * 🚧 You have to make sure that your module is in `dependencies` and not in the` devDependencies`,
* which will ensure that the electron-builder can package it correctly * which will ensure that the electron-builder can package it correctly
* @example * @example
* { * {
* 'electron-store': 'const Store = require("electron-store"); export default Store;', * 'electron-store': 'const Store = require("electron-store"); export default Store;',
* } * }
*/ */
), ),
], ],
base: './', base: './',
@ -44,7 +44,7 @@ export default defineConfig({
* For usage of Electron and NodeJS APIs in the Renderer process * For usage of Electron and NodeJS APIs in the Renderer process
* @see https://github.com/caoxiemeihao/electron-vue-vite/issues/52 * @see https://github.com/caoxiemeihao/electron-vue-vite/issues/52
*/ */
export function resolveElectron( export function resolveElectron(
resolves: Parameters<typeof resolve>[0] = {} resolves: Parameters<typeof resolve>[0] = {}
): Plugin { ): Plugin {
const builtins = builtinModules.filter((t) => !t.startsWith('_')) const builtins = builtinModules.filter((t) => !t.startsWith('_'))
@ -60,35 +60,35 @@ export function resolveElectron(
function electronExport() { function electronExport() {
return ` return `
/** /**
* For all exported modules see https://www.electronjs.org/docs/latest/api/clipboard -> Renderer Process Modules * For all exported modules see https://www.electronjs.org/docs/latest/api/clipboard -> Renderer Process Modules
*/ */
const electron = require("electron"); const electron = require("electron");
const { const {
clipboard, clipboard,
nativeImage, nativeImage,
shell, shell,
contextBridge, contextBridge,
crashReporter, crashReporter,
ipcRenderer, ipcRenderer,
webFrame, webFrame,
desktopCapturer, desktopCapturer,
deprecate, deprecate,
} = electron; } = electron;
export { export {
electron as default, electron as default,
clipboard, clipboard,
nativeImage, nativeImage,
shell, shell,
contextBridge, contextBridge,
crashReporter, crashReporter,
ipcRenderer, ipcRenderer,
webFrame, webFrame,
desktopCapturer, desktopCapturer,
deprecate, deprecate,
} }
` `
} }
function builtinModulesExport(modules: string[]) { function builtinModulesExport(modules: string[]) {
@ -102,12 +102,12 @@ export function resolveElectron(
.map((attr) => `export const ${attr} = M.${attr}`) .map((attr) => `export const ${attr} = M.${attr}`)
.join(';\n') + ';' .join(';\n') + ';'
const nodeModuleCode = ` const nodeModuleCode = `
${requireModule} ${requireModule}
${exportDefault} ${exportDefault}
${exportMembers} ${exportMembers}
` `
return { [moduleId]: nodeModuleCode } return { [moduleId]: nodeModuleCode }
}) })