mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-08-25 22:31:20 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cd8fea0c28 | ||
|
b361d2af2c | ||
|
1fd0096b81 | ||
|
f652719e90 |
@@ -66,6 +66,5 @@ export default {
|
|||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
- [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#dependencies-vs-devdependencies)
|
- [dependencies vs devDependencies](https://github.com/electron-vite/vite-plugin-electron-renderer#dependencies-vs-devdependencies)
|
||||||
- [Using C/C++ native addons in Electron-Renderer](https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#load-nodejs-cc-native-modules)
|
- [C/C++ addons, Node.js modules - Pre-Bundling](https://github.com/electron-vite/vite-plugin-electron-renderer#dependency-pre-bundling)
|
||||||
- [Node.js ESM packages](https://github.com/electron-vite/vite-plugin-electron/tree/main/packages/electron-renderer#nodejs-esm-packages) (e.g. `execa` `node-fetch`)
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "electron-vue-vite",
|
"name": "electron-vue-vite",
|
||||||
"version": "2.1.0",
|
"version": "2.0.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>",
|
||||||
@@ -13,14 +13,15 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": "^14.18.0 || >=16.0.0"
|
"node": "^14.18.0 || >=16.0.0"
|
||||||
},
|
},
|
||||||
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^3.1.2",
|
"@vitejs/plugin-vue": "^3.1.2",
|
||||||
"electron": "^21.1.0",
|
"electron": "^21.1.0",
|
||||||
"electron-builder": "^23.3.3",
|
"electron-builder": "^23.3.3",
|
||||||
"typescript": "^4.8.4",
|
"typescript": "^4.8.4",
|
||||||
"vite": "^3.2.2",
|
"vite": "^3.2.2",
|
||||||
"vite-electron-plugin": "^0.5.0",
|
"vite-plugin-electron": "^0.10.4",
|
||||||
"vite-plugin-electron-renderer": "^0.10.2",
|
"vite-plugin-electron-renderer": "^0.11.1",
|
||||||
"vue": "^3.2.40",
|
"vue": "^3.2.40",
|
||||||
"vue-tsc": "^1.0.9"
|
"vue-tsc": "^1.0.9"
|
||||||
},
|
},
|
||||||
@@ -36,4 +37,4 @@
|
|||||||
"vue3",
|
"vue3",
|
||||||
"vue"
|
"vue"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -1,36 +1,68 @@
|
|||||||
import { rmSync } from 'fs'
|
import { rmSync } from 'fs'
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import electron from 'vite-electron-plugin'
|
import electron from 'vite-plugin-electron'
|
||||||
import { customStart, loadViteEnv } from 'vite-electron-plugin/plugin'
|
|
||||||
import renderer from 'vite-plugin-electron-renderer'
|
import renderer from 'vite-plugin-electron-renderer'
|
||||||
import pkg from './package.json'
|
import pkg from './package.json'
|
||||||
|
|
||||||
rmSync('dist-electron', { recursive: true, force: true })
|
rmSync('dist-electron', { recursive: true, force: true })
|
||||||
|
const sourcemap = !!process.env.VSCODE_DEBUG
|
||||||
|
const isBuild = process.argv.slice(2).includes('build')
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
electron({
|
electron([
|
||||||
include: ['electron'],
|
{
|
||||||
transformOptions: {
|
// Main-Process entry file of the Electron App.
|
||||||
sourcemap: !!process.env.VSCODE_DEBUG,
|
entry: 'electron/main/index.ts',
|
||||||
|
onstart(options) {
|
||||||
|
if (process.env.VSCODE_DEBUG) {
|
||||||
|
console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')
|
||||||
|
} else {
|
||||||
|
options.startup()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
vite: {
|
||||||
|
build: {
|
||||||
|
sourcemap,
|
||||||
|
minify: isBuild,
|
||||||
|
outDir: 'dist-electron/main',
|
||||||
|
rollupOptions: {
|
||||||
|
external: Object.keys(pkg.dependencies),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
{
|
||||||
...(process.env.VSCODE_DEBUG
|
entry: 'electron/preload/index.ts',
|
||||||
? [
|
onstart(options) {
|
||||||
// Will start Electron via VSCode Debug
|
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
|
||||||
customStart(debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App'))),
|
// instead of restarting the entire Electron App.
|
||||||
]
|
options.reload()
|
||||||
: []),
|
},
|
||||||
// Allow use `import.meta.env.VITE_SOME_KEY` in Electron-Main
|
vite: {
|
||||||
loadViteEnv(),
|
build: {
|
||||||
],
|
sourcemap,
|
||||||
}),
|
minify: isBuild,
|
||||||
|
outDir: 'dist-electron/preload',
|
||||||
|
rollupOptions: {
|
||||||
|
external: Object.keys(pkg.dependencies),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]),
|
||||||
// Use Node.js API in the Renderer-process
|
// Use Node.js API in the Renderer-process
|
||||||
renderer({
|
renderer({
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
|
optimizeDeps: {
|
||||||
|
include: [
|
||||||
|
'fs/promises',
|
||||||
|
'process',
|
||||||
|
],
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
server: process.env.VSCODE_DEBUG ? (() => {
|
server: process.env.VSCODE_DEBUG ? (() => {
|
||||||
@@ -45,11 +77,3 @@ export default defineConfig({
|
|||||||
assetsDir: '', // #287
|
assetsDir: '', // #287
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user