vue3+vite5+electron+node20版本桌面应用打包出错

首先是vite5版本不支持require引入了,暂时的解决办法是在package.json中删掉  "type": "module",不报错但是有警告:The CJS build of Vite's Node API is deprecated.

再有就是打包时在github下载东西时超时报错,解决办法是在项目根目录新建 .npmrc 文件写入国内资源:

ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/

ELECTRON_BUILDER_BINARIES_MIRROR=http://npm.taobao.org/mirrors/electron-builder-binaries/

 

如果配置完成了又报错:

⨯ cannot execute  cause=exit status 2
                    out=
    7-Zip (a) 21.07 (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26

    Scanning the drive for archives:
    1 file, 5635384 bytes (5504 KiB)

.

.

.

.

这个报错是没有管理员权限,使用管理员身份运行PowerShell,cd进入项目目录执行打包命令即可

win11 右键点击win图标

打开终端管理员进入项目目录,执行打包命令就OK啦,之后就可以正常在vscode中进行打包了。

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
搭建一个基于 Vue3、ViteElectron 的项目,可以按照以下步骤进行: 1. 创建一个空的文件夹,打开终端并进入该文件夹,执行以下命令: ```bash npm init -y ``` 2. 安装依赖: ```bash npm install --save-dev vue@next @vitejs/plugin-vue @vue/compiler-sfc electron vite electron-builder ``` 3. 在项目根目录下创建一个 `src` 文件夹,用于存放 Vue 代码。 4. 在项目根目录下创建一个 `main.js` 文件,用于启动 Electron 应用程序。在该文件中编写以下代码: ```javascript const { app, BrowserWindow } = require('electron') const path = require('path') function createWindow () { // 创建浏览器窗口 const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false, enableRemoteModule: true, }, }) // 加载 Vue 项目 win.loadURL(`file://${path.join(__dirname, '../dist/index.html')}`) } app.whenReady().then(() => { createWindow() app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } }) }) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) ``` 5. 在项目根目录下创建一个 `vite.config.js` 文件,用于配置 Vite。在该文件中编写以下代码: ```javascript const { defineConfig } = require('vite') const vue = require('@vitejs/plugin-vue') module.exports = defineConfig({ plugins: [vue()], build: { outDir: '../dist', }, }) ``` 6. 在 `package.json` 文件中添加以下脚本: ```json "scripts": { "serve": "vite", "build": "vite build", "electron": "electron ." } ``` 7. 在终端中执行以下命令启动开发服务器: ```bash npm run serve ``` 8. 在终端中执行以下命令启动 Electron 应用程序: ```bash npm run electron ``` 现在,你已经成功搭建了一个 Vue3、ViteElectron 的项目。可以在 `src` 文件夹中编写 Vue 代码,然后使用 `npm run build` 命令打包应用程序。打包完成后,可以在 `dist` 文件夹中找到生成的可执行文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值