From 9a12184f9b2da02b82a6f5627858a3041d639f73 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 25 Feb 2023 22:09:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A1=8C=E9=9D=A2=E7=AB=AF=E6=96=B0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=89=93=E5=BC=80=E4=BB=BB=E5=8A=A1=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8F=91=E8=B5=B7=E8=81=8A=E5=A4=A9=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd | 2 +- electron/build.js | 2 +- electron/electron-preload.js | 3 +++ vite.config.js | 12 ++++-------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd b/cmd index 0d937af9b..9e0f6f082 100755 --- a/cmd +++ b/cmd @@ -135,7 +135,7 @@ run_electron() { else mkdir -p ./electron/public cp ./electron/index.html ./electron/public/index.html - npx vite build -- fromcmd electron + npx vite build -- fromcmd electronBuild fi node ./electron/build.js $argv } diff --git a/electron/build.js b/electron/build.js index f5296267e..65d71b382 100644 --- a/electron/build.js +++ b/electron/build.js @@ -193,7 +193,7 @@ function startBuild(data, publish, release) { if (["dev"].includes(argv[2])) { // 开发模式 fs.writeFileSync(devloadCachePath, utils.formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8'); - child_process.spawn("npx", ["vite", "--", "fromcmd", "electron"], {stdio: "inherit"}); + child_process.spawn("npx", ["vite", "--", "fromcmd", "electronDev"], {stdio: "inherit"}); child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"}); } else if (["app"].includes(argv[2])) { // 编译给app diff --git a/electron/electron-preload.js b/electron/electron-preload.js index d032682c9..abccd3fce 100644 --- a/electron/electron-preload.js +++ b/electron/electron-preload.js @@ -50,6 +50,9 @@ contextBridge.exposeInMainWorld( sendMessage: function (action, args) { ipcRenderer.send(action, args); }, + sendSyncMessage: function (action, args) { + ipcRenderer.sendSync(action, args) + }, listenOnce: function (action, callback) { ipcRenderer.once(action, function (event, args) { callback(args); diff --git a/vite.config.js b/vite.config.js index 2e742afe6..d43aeb8d2 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,11 +7,10 @@ import vitePluginFileCopy from 'vite-plugin-file-copy'; import autoprefixer from 'autoprefixer'; const argv = process.argv; -const isCmd = argv.includes('fromcmd'); -const isElectron = argv.includes('electron'); -const publicPath = isElectron ? 'electron/public' : 'public'; +const basePath = argv.includes('electronBuild') ? './' : '/'; +const publicPath = argv.includes('electronBuild') ? 'electron/public' : 'public'; -if (!isCmd) { +if (!argv.includes('fromcmd')) { spawnSync("npx", [resolve(__dirname, 'cmd'), argv.includes("build") ? "build" : "dev"], {stdio: "inherit"}); process.exit() } @@ -22,7 +21,7 @@ export default defineConfig(({command, mode}) => { const port = parseInt(env['APP_DEV_PORT']) return { - base: isElectron ? './' : '/', + base: basePath, publicDir: publicPath, server: { host, @@ -39,9 +38,6 @@ export default defineConfig(({command, mode}) => { }, extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] }, - define: { - 'process.env.NODE_ENV': command === 'serve' ? '"development"' : '"production"', - }, build: { manifest: true, outDir: publicPath,