diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cfc2cda..29a1e2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,12 +24,12 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 18 - name: Install Dependencies run: npm install diff --git a/.gitignore b/.gitignore index 3c0d0bb..f798fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,12 @@ lerna-debug.log* node_modules dist dist-ssr +dist-electron +release *.local # Editor directories and files +.vscode/.debug.env .idea .DS_Store *.suo @@ -21,9 +24,7 @@ dist-ssr *.sln *.sw? -release -.vscode/.debug.env +# lockfile package-lock.json pnpm-lock.yaml -yarn.lock -dist-electron +yarn.lock \ No newline at end of file diff --git a/.vscode/.debug.script.mjs b/.vscode/.debug.script.mjs index 2066b94..e3674cb 100644 --- a/.vscode/.debug.script.mjs +++ b/.vscode/.debug.script.mjs @@ -1,8 +1,8 @@ -import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' -import { createRequire } from 'module' -import { spawn } from 'child_process' +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import { createRequire } from 'node:module' +import { spawn } from 'node:child_process' const pkg = createRequire(import.meta.url)('../package.json') const __dirname = path.dirname(fileURLToPath(import.meta.url)) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3fed951..3d01d65 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,7 +22,7 @@ "configurations": [ { "name": "Debug Main Process", - "type": "pwa-node", + "type": "node", "request": "launch", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", "windows": { @@ -39,7 +39,7 @@ "name": "Debug Renderer Process", "port": 9229, "request": "attach", - "type": "pwa-chrome", + "type": "chrome", "timeout": 60000, "skipFiles": [ "/**", diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a96bc9..1e3e2cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,11 @@ { "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true, + "typescript.tsc.autoDetect": "off", "json.schemas": [ { "fileMatch": [ - "/*electron-builder.json5" + "/*electron-builder.json5", + "/*electron-builder.json" ], "url": "https://json.schemastore.org/electron-builder" } diff --git a/README.md b/README.md index 4d3fbd4..359d4a7 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ npm create electron-vite -![electron-vite-vue.gif](https://github.com/electron-vite/electron-vite-vue/blob/main/public/electron-vite-vue.gif?raw=true) +![electron-vite-vue.gif](/public/electron-vite-vue.gif) ## Debug diff --git a/electron-builder.json5 b/electron-builder.json5 index 65395f9..cc8c811 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -4,6 +4,7 @@ { "appId": "YourAppID", "asar": true, + "icon": "public/favicon.ico", "directories": { "output": "release/${version}" }, diff --git a/electron/main/index.ts b/electron/main/index.ts index f952c00..f209629 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,3 +1,7 @@ +import { app, BrowserWindow, shell, ipcMain } from 'electron' +import { release } from 'node:os' +import { join } from 'node:path' + // The built directory structure // // ├─┬ dist-electron @@ -14,10 +18,6 @@ process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL ? join(process.env.DIST_ELECTRON, '../public') : process.env.DIST -import { app, BrowserWindow, shell, ipcMain } from 'electron' -import { release } from 'os' -import { join } from 'path' - // Disable GPU Acceleration for Windows 7 if (release().startsWith('6.1')) app.disableHardwareAcceleration() @@ -99,7 +99,7 @@ app.on('activate', () => { }) // New window example arg: new windows url -ipcMain.handle('open-win', (event, arg) => { +ipcMain.handle('open-win', (_, arg) => { const childWindow = new BrowserWindow({ webPreferences: { preload, diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 0ee2dcc..ebf1276 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -1,5 +1,5 @@ function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) { - return new Promise(resolve => { + return new Promise((resolve) => { if (condition.includes(document.readyState)) { resolve(true) } else { @@ -85,7 +85,7 @@ function useLoading() { const { appendLoading, removeLoading } = useLoading() domReady().then(appendLoading) -window.onmessage = ev => { +window.onmessage = (ev) => { ev.data.payload === 'removeLoading' && removeLoading() } diff --git a/index.html b/index.html index 275b440..2c2325b 100644 --- a/index.html +++ b/index.html @@ -2,10 +2,10 @@ - + - Vite App + Electron + Vite + Vue
diff --git a/package.json b/package.json index 816ea98..3cf7445 100644 --- a/package.json +++ b/package.json @@ -6,35 +6,32 @@ "author": "草鞋没号 <308487730@qq.com>", "license": "MIT", "private": true, - "scripts": { - "dev": "vite", - "build": "vue-tsc --noEmit && vite build && electron-builder" - }, - "engines": { - "node": "^14.18.0 || >=16.0.0" - }, - "dependencies": {}, - "devDependencies": { - "@vitejs/plugin-vue": "^4.0.0", - "electron": "^22.0.0", - "electron-builder": "^23.3.3", - "typescript": "^4.8.4", - "vite": "^4.0.0", - "vite-plugin-electron": "^0.11.1", - "vite-plugin-electron-renderer": "^0.11.3", - "vue": "^3.2.40", - "vue-tsc": "^1.0.9" - }, - "debug": { - "env": { - "VITE_DEV_SERVER_URL": "http://127.0.0.1:3344" - } - }, "keywords": [ "electron", "rollup", "vite", "vue3", "vue" - ] + ], + "debug": { + "env": { + "VITE_DEV_SERVER_URL": "http://127.0.0.1:3344/" + } + }, + "scripts": { + "dev": "vite", + "build": "vue-tsc --noEmit && vite build && electron-builder", + "preview": "vite preview" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^4.0.0", + "electron": "^22.0.0", + "electron-builder": "^23.6.0", + "typescript": "^4.9.4", + "vite": "^4.0.3", + "vite-plugin-electron": "^0.11.1", + "vite-plugin-electron-renderer": "^0.11.3", + "vue": "^3.2.45", + "vue-tsc": "^1.0.16" + } } diff --git a/public/favicon.ico b/public/favicon.ico index df36fcf..843ea24 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/node.png b/public/node.png deleted file mode 100644 index 1cd6519..0000000 Binary files a/public/node.png and /dev/null differ diff --git a/public/node.svg b/public/node.svg new file mode 100644 index 0000000..38d4eaa --- /dev/null +++ b/public/node.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/vite.svg b/public/vite.svg similarity index 100% rename from src/assets/vite.svg rename to public/vite.svg diff --git a/src/App.vue b/src/App.vue index 36f8b32..d679871 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,67 +1,50 @@