Skip to content

Commit

Permalink
优化:重构打包方式
Browse files Browse the repository at this point in the history
  • Loading branch information
modstart committed Dec 13, 2024
1 parent 645e7c8 commit d5625e0
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ database.db

src/lang/source-use.json
/data
/build/
2 changes: 1 addition & 1 deletion electron/lib/env-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
? path.join(process.env.APP_ROOT, 'public')
: RENDERER_DIST

export const preloadDefault = path.join(MAIN_DIST, 'preload/index.mjs')
export const preloadDefault = path.join(MAIN_DIST, 'preload/index.cjs')

export const rendererLoadPath = (window: BrowserWindow | BrowserView, fileName: string) => {
if (!isPackaged && process.env.VITE_DEV_SERVER_URL) {
Expand Down
10 changes: 5 additions & 5 deletions electron/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from "node:fs";
import Showdown from "showdown"
import iconvLite from "iconv-lite";
import chardet from "chardet";
import {Iconv} from "iconv"
// import {Iconv} from "iconv"

export const EncodeUtil = {
base64Encode(str: string) {
Expand Down Expand Up @@ -39,10 +39,10 @@ export const IconvUtil = {
},
bufferToUtf8(buffer: Buffer) {
const encoding = chardet.detect(buffer)
if ('ISO-2022-CN' === encoding) {
const iconvInstance = new Iconv('ISO-2022-CN', 'UTF-8//TRANSLIT//IGNORE');
return iconvInstance.convert(buffer).toString()
}
// if ('ISO-2022-CN' === encoding) {
// const iconvInstance = new Iconv('ISO-2022-CN', 'UTF-8//TRANSLIT//IGNORE');
// return iconvInstance.convert(buffer).toString()
// }
return iconvLite.decode(buffer, encoding).toString()
},
detect(buffer: Uint8Array) {
Expand Down
2 changes: 1 addition & 1 deletion electron/mapi/keys/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const register = () => {
} else {
focusedWindow.webContents.openDevTools({
mode: 'detach',
activate: false,
activate: true,
title: 'FocusedWindow',
});
}
Expand Down
2 changes: 1 addition & 1 deletion electron/page/thirdPartyImageBeautifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {preloadDefault, rendererLoadPath} from "../lib/env-main";
import {preloadDefault} from "../lib/env-main";
import {AppRuntime} from "../mapi/env";
import {BrowserWindow} from "electron";
import {Page} from "./index";
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@
"@devicefarmer/adbkit": "^3.2.6",
"@electron-toolkit/preload": "^3.0.1",
"@electron-toolkit/utils": "^3.0.0",
"@electron/remote": "^2.1.2",
"@types/showdown": "^2.0.6",
"@xterm/addon-fit": "^0.10.0",
"@xterm/xterm": "^5.5.0",
"axios": "^1.7.2",
"chardet": "^2.0.0",
"date-and-time": "^3.4.1",
"dayjs": "^1.11.12",
"electron-context-menu": "^4.0.4",
"ffmpeg-static": "^5.2.0",
"fix-path": "^4.0.0",
"iconv": "^3.0.1",
"iconv-lite": "^0.6.3",
"js-base64": "^3.7.7",
"lodash-es": "^4.17.21",
Expand All @@ -79,5 +82,8 @@
"vue-command": "^35.2.1",
"vue-i18n": "^9.13.1",
"vue-router": "^4.4.0"
},
"optionalDependencies": {
"node-mac-permissions": "^2.4.0"
}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/third-party/image-beautifier/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="./assets/favicon-Bv5yausS.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="module" crossorigin src="./assets/index-CRsOhn0p.js"></script>
<script type="module" crossorigin src="./assets/index-SmyfLWDC.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BcWrJNLv.css">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Device/DeviceActionScreenshot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const doScreenshot = async () => {
const image = await window.$mapi.adb.screencap(props.device.id)
const base64 = 'data:image/png;base64,' + image
await window.$mapi.page.open('thirdPartyImageBeautifier')
await window.$mapi.event.callThirdParty('thirdPartyImageBeautifier', 'doSetImage', base64)
await window.$mapi.event.callPage('thirdPartyImageBeautifier', 'doSetImage', base64)
} catch (error) {
Dialog.tipError(mapError(error))
}
Expand Down
34 changes: 23 additions & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'node:fs'
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron/simple'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import pkg from './package.json'
import path from "node:path";
import {AppConfig} from "./src/config";
Expand Down Expand Up @@ -53,8 +54,8 @@ export default defineConfig(({command}) => {

},
},
electron({
main: {
electron([
{
// Shortcut of `build.lib.entry`
entry: 'electron/main/index.ts',
onstart({startup}) {
Expand All @@ -79,26 +80,37 @@ export default defineConfig(({command}) => {
},
},
},
preload: {
{
// Shortcut of `build.rollupOptions.input`.
// Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
input: 'electron/preload/index.ts',
entry: 'electron/preload/index.ts',
onstart({reload}) {
// Notify the Renderer process to reload the page when the Preload scripts build is complete,
// instead of restarting the entire Electron App.
reload()
},
vite: {
build: {
sourcemap: sourcemap ? 'inline' : undefined, // #332
target: 'es2015',
sourcemap: undefined, // #332
minify: minify,
outDir: 'dist-electron/preload',
lib: {
formats: ['cjs'],
},
rollupOptions: {
external: externalPackages,
output: {
format: 'cjs',
entryFileNames: '[name].cjs',
compact: false,
},
},
},
},
},
// Ployfill the Electron and Node.js API for Renderer process.
// If you want use Node.js in Renderer process, the `nodeIntegration` needs to be enabled in the Main process.
// See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
renderer: {},
}),
]),
renderer(),
],
build: {
sourcemap: sourcemap,
Expand Down

0 comments on commit d5625e0

Please sign in to comment.