mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-01-19 03:46:35 +08:00
Merge branch 'main' of github.com:caoxiemeihao/electron-vue-vite into main
This commit is contained in:
commit
9bd69b156b
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ dist-ssr
|
|||||||
|
|
||||||
release
|
release
|
||||||
.vscode/.debug.env
|
.vscode/.debug.env
|
||||||
|
dist-electron
|
||||||
|
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@ -32,7 +32,8 @@
|
|||||||
"--remote-debugging-port=9229",
|
"--remote-debugging-port=9229",
|
||||||
"."
|
"."
|
||||||
],
|
],
|
||||||
"envFile": "${workspaceFolder}/.vscode/.debug.env"
|
"envFile": "${workspaceFolder}/.vscode/.debug.env",
|
||||||
|
"console": "integratedTerminal"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Debug Renderer Process",
|
"name": "Debug Renderer Process",
|
||||||
|
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
@ -12,6 +12,7 @@
|
|||||||
"owner": "typescript",
|
"owner": "typescript",
|
||||||
"fileLocation": "relative",
|
"fileLocation": "relative",
|
||||||
"pattern": {
|
"pattern": {
|
||||||
|
// TODO: correct "regexp"
|
||||||
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
"regexp": "^([a-zA-Z]\\:\/?([\\w\\-]\/?)+\\.\\w+):(\\d+):(\\d+): (ERROR|WARNING)\\: (.*)$",
|
||||||
"file": 1,
|
"file": 1,
|
||||||
"line": 3,
|
"line": 3,
|
||||||
@ -21,8 +22,7 @@
|
|||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"activeOnStart": true,
|
"activeOnStart": true,
|
||||||
"beginsPattern": "^.*building for development.*$",
|
"endsPattern": "^.*[startup] Electron App.*$",
|
||||||
"endsPattern": "built in [0-9]*ms.*$",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"output": "release/${version}"
|
"output": "release/${version}"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
"dist-electron",
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"mac": {
|
"mac": {
|
||||||
|
19
electron/electron-env.d.ts
vendored
19
electron/electron-env.d.ts
vendored
@ -1,22 +1,9 @@
|
|||||||
/// <reference types="vite-plugin-electron/electron-env" />
|
/// <reference types="vite-electron-plugin/electron-env" />
|
||||||
|
|
||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
interface ProcessEnv {
|
interface ProcessEnv {
|
||||||
/**
|
VSCODE_DEBUG?: 'true'
|
||||||
* The built directory structure
|
DIST_ELECTRON: string
|
||||||
*
|
|
||||||
* ```tree
|
|
||||||
* ├─┬ dist
|
|
||||||
* │ ├─┬ electron
|
|
||||||
* │ │ ├─┬ main
|
|
||||||
* │ │ │ └── index.js
|
|
||||||
* │ │ └─┬ preload
|
|
||||||
* │ │ └── index.js
|
|
||||||
* │ ├── index.html
|
|
||||||
* │ ├── ...other-static-files-from-public
|
|
||||||
* │
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
DIST: string
|
DIST: string
|
||||||
/** /dist/ or /public/ */
|
/** /dist/ or /public/ */
|
||||||
PUBLIC: string
|
PUBLIC: string
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
// The built directory structure
|
// The built directory structure
|
||||||
//
|
//
|
||||||
|
// ├─┬ dist-electron
|
||||||
|
// │ ├─┬ main
|
||||||
|
// │ │ └── index.js > Electron-Main
|
||||||
|
// │ └─┬ preload
|
||||||
|
// │ └── index.js > Preload-Scripts
|
||||||
// ├─┬ dist
|
// ├─┬ dist
|
||||||
// │ ├─┬ electron
|
// │ └── index.html > Electron-Renderer
|
||||||
// │ │ ├─┬ main
|
//
|
||||||
// │ │ │ └── index.js
|
process.env.DIST_ELECTRON = join(__dirname, '..')
|
||||||
// │ │ └─┬ preload
|
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
|
||||||
// │ │ └── index.js
|
process.env.PUBLIC = app.isPackaged ? process.env.DIST : join(process.env.DIST_ELECTRON, '../public')
|
||||||
// │ ├── index.html
|
|
||||||
// │ ├── ...other-static-files-from-public
|
|
||||||
// │
|
|
||||||
process.env.DIST = join(__dirname, '../..')
|
|
||||||
process.env.PUBLIC = app.isPackaged ? process.env.DIST : join(process.env.DIST, '../public')
|
|
||||||
|
|
||||||
import { app, BrowserWindow, shell, ipcMain } from 'electron'
|
import { app, BrowserWindow, shell, ipcMain } from 'electron'
|
||||||
import { release } from 'os'
|
import { release } from 'os'
|
||||||
@ -35,7 +35,7 @@ if (!app.requestSingleInstanceLock()) {
|
|||||||
let win: BrowserWindow | null = null
|
let win: BrowserWindow | null = null
|
||||||
// Here, you can also use other preload
|
// Here, you can also use other preload
|
||||||
const preload = join(__dirname, '../preload/index.js')
|
const preload = join(__dirname, '../preload/index.js')
|
||||||
const url = process.env.VITE_DEV_SERVER_URL as string
|
const url = process.env.VITE_DEV_SERVER_URL
|
||||||
const indexHtml = join(process.env.DIST, 'index.html')
|
const indexHtml = join(process.env.DIST, 'index.html')
|
||||||
|
|
||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
|
10
package.json
10
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "electron-vue-vite",
|
"name": "electron-vue-vite",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"main": "dist/electron/main/index.js",
|
"main": "dist-electron/main/index.js",
|
||||||
"description": "Really simple Electron + Vue + Vite boilerplate.",
|
"description": "Really simple Electron + Vue + Vite boilerplate.",
|
||||||
"author": "草鞋没号 <308487730@qq.com>",
|
"author": "草鞋没号 <308487730@qq.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -15,18 +15,16 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^3.0.1",
|
"@vitejs/plugin-vue": "^3.0.1",
|
||||||
"electron": "^20.0.2",
|
"electron": "^21.0.1",
|
||||||
"electron-builder": "^23.3.3",
|
"electron-builder": "^23.3.3",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"vite": "^3.0.8",
|
"vite": "^3.0.8",
|
||||||
"vite-plugin-electron": "^0.9.3",
|
"vite-electron-plugin": "^0.4.1",
|
||||||
"vue": "^3.2.37",
|
"vue": "^3.2.37",
|
||||||
"vue-tsc": "^0.40.1"
|
"vue-tsc": "^0.40.1"
|
||||||
},
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"env": {
|
"env": {
|
||||||
"VITE_DEV_SERVER_HOSTNAME": "127.0.0.1",
|
|
||||||
"VITE_DEV_SERVER_PORT": 3344,
|
|
||||||
"VITE_DEV_SERVER_URL": "http://127.0.0.1:3344"
|
"VITE_DEV_SERVER_URL": "http://127.0.0.1:3344"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you enables use of Node.js API in the Renderer-process
|
||||||
|
* ```
|
||||||
|
* npm i -D vite-plugin-electron-renderer
|
||||||
|
* ```
|
||||||
|
* @see - https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#electron-renderervite-serve
|
||||||
|
*/
|
||||||
// import './samples/node-api'
|
// import './samples/node-api'
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
|
@ -1,49 +1,41 @@
|
|||||||
import { rmSync } from 'fs'
|
import { rmSync } from 'fs'
|
||||||
import path from 'path'
|
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import electron, { onstart } from 'vite-plugin-electron'
|
import electron from 'vite-electron-plugin'
|
||||||
|
import { customStart } from 'vite-electron-plugin/plugin'
|
||||||
import pkg from './package.json'
|
import pkg from './package.json'
|
||||||
|
|
||||||
rmSync('dist', { recursive: true, force: true }) // v14.14.0
|
rmSync('dist-electron', { recursive: true, force: true })
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
electron({
|
electron({
|
||||||
main: {
|
include: ['electron'],
|
||||||
entry: 'electron/main/index.ts',
|
transformOptions: {
|
||||||
vite: {
|
sourcemap: !!process.env.VSCODE_DEBUG,
|
||||||
build: {
|
|
||||||
// For Debug
|
|
||||||
sourcemap: true,
|
|
||||||
outDir: 'dist/electron/main',
|
|
||||||
},
|
|
||||||
// Will start Electron via VSCode Debug
|
|
||||||
plugins: [process.env.VSCODE_DEBUG ? onstart() : null],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
preload: {
|
// Will start Electron via VSCode Debug
|
||||||
input: {
|
plugins: process.env.VSCODE_DEBUG
|
||||||
// You can configure multiple preload here
|
? [customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')))]
|
||||||
index: path.join(__dirname, 'electron/preload/index.ts'),
|
: undefined,
|
||||||
},
|
|
||||||
vite: {
|
|
||||||
build: {
|
|
||||||
// For Debug
|
|
||||||
sourcemap: 'inline',
|
|
||||||
outDir: 'dist/electron/preload',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Enables use of Node.js API in the Renderer-process
|
|
||||||
// https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#electron-renderervite-serve
|
|
||||||
renderer: {},
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
server: process.env.VSCODE_DEBUG ? {
|
server: process.env.VSCODE_DEBUG ? (() => {
|
||||||
host: pkg.debug.env.VITE_DEV_SERVER_HOSTNAME,
|
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
|
||||||
port: pkg.debug.env.VITE_DEV_SERVER_PORT,
|
return {
|
||||||
} : undefined,
|
host: url.hostname,
|
||||||
|
port: +url.port,
|
||||||
|
}
|
||||||
|
})() : undefined,
|
||||||
|
clearScreen: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function debounce<Fn extends (...args: any[]) => void>(fn: Fn, delay = 299) {
|
||||||
|
let t: NodeJS.Timeout
|
||||||
|
return ((...args) => {
|
||||||
|
clearTimeout(t)
|
||||||
|
t = setTimeout(() => fn(...args), delay)
|
||||||
|
}) as Fn
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user