base: VITE_APP_ENV === 'production' ? './' : './',
plugins: createVitePlugins(env, command === 'build'),
resolve: {
// https://cn.vitejs.dev/config/#resolve-alias
alias: {
// 设置路径
'~': path.resolve(__dirname, './'),
// 设置别名
'@': path.resolve(__dirname, './src')
},
// https://cn.vitejs.dev/config/#resolve-extensions
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
const { app, BrowserWindow, globalShortcut } = require('electron')
const path = require('path')
const createWindow = (accelerator, callback) => {
const win = new BrowserWindow({
width: 1920,
height: 1080,
minWidth: 384,
minHeight: 216,
maxWidth: 1920,
maxHeight: 1080,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
win.loadURL(`file://${__dirname}/static/index.html`)
win.webContents.openDevTools()
}
app.whenReady().then(() => {
createWindow()
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})
{
"name": "electron-app",
"version": "1.0.0",
"description": "NanHu",
"main": "main.js",
"author": "archie",
"license": "MIT",
"dependencies": {
"core-js": "^2.4.1",
"electron-packager": "^12.1.0",
"electron-updater": "^4.0.0"
},
"devDependencies": {
"electron": "^20.0.1",
"electron-packager": "^16.0.0"
},
"scripts": {
"start": "electron .",
"packager": "electron-packager ./ App --platform=win32 --arch=x64 --electron-version=3.0.0 --overwrite"
},
"build": {
"win": {
"requestedExecutionLevel": "highestAvailable",
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
]
},
"appId": "NanHu",
"artifactName": "NanHu-${version}-${arch}.${ext}",
"nsis": {
"artifactName": "NanHu-${version}-${arch}.${ext}"
},
"extraResources": [
{
"from": "./static/",
"to": "/",
"filter": [
"**/*"
]
}
]
}
}
./
修改成/
的话,连js也加载不到就一直显示下图的加载页面你可能需要配置 vitejs#publicdir
建议你看下这篇博客Electron+vue的使用