首页 > 其他分享 >electron+ vue3基础模板

electron+ vue3基础模板

时间:2024-11-26 09:56:49浏览次数:8  
标签:vue plugin electron 模板 vue3 main true vite

1.创建一个vue3项目:

npm create vite@latest electron-desktop-tool

 

2.在安装 electron之前需要先配置一下 安装源 

在根目录下新建一个 .npmrc文件

strict-ssl=false
registry=https://registry.npmmirror.com/
electron_mirror=https://registry.npmmirror.com/-/binary/electron/
electron_builder_binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
# ELECTRON_BUILDER_BINARIES_MIRROR=https://mirrors.huaweicloud.com/electron-builder-binaries/ 

 

3.安装electron依赖

npm install -D electron
npm install -D electron-builder
npm install -D electron-devtools-installer
npm install -D vite-plugin-electron

 

4.在vite.config.ts中配置vite-plugin-electron 插件入口

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        electron({
            // 主进程入口文件
            entry: './src-electron/main.js'
        })
    ],
    /*开发服务器选项*/
    server: {
        // 端口
        port: 3000,
    }
})

 

5.新建一个src-electron 文件用来写electron的代码,在它下面创建一个 main.js文件 用来写主进程代码

// src-electron/main.js
const { app, BrowserWindow, Menu  } = require('electron')
const { join } = require('path')

// 屏蔽安全警告
// ectron Security Warning (Insecure Content-Security-Policy)
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'

// 创建浏览器窗口时,调用这个函数。
const createWindow = () => {
    const win = new BrowserWindow({
        width: 1600,
        height: 700,
        // title: '11111111',
        icon: join(__dirname, '../public/login1.png'),
    })

    

    // win.loadURL('http://localhost:3000')
    // development模式
    if(process.env.VITE_DEV_SERVER_URL) {
        win.loadURL(process.env.VITE_DEV_SERVER_URL)
        // 开启调试台
        win.webContents.openDevTools()
    }else {
        win.loadFile(join(__dirname, '../dist/index.html'))
    }

    Menu.setApplicationMenu(null);
}

// Electron 会在初始化后并准备
app.whenReady().then(() => {
    createWindow()
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})

 

6.在package.json "type": "module", 删除掉并且配置main字段以及添加打包配置build

{
  "name": "electron-desktop-tool",
  "private": true,
  "version": "0.0.0",
  "main": "./src-electron/main.js",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc -b && vite build",
    "preview": "vite preview",
    "electron:build": "vite build && electron-builder"
  },
  "build": {
    "productName": "ElectronDeskTopTool",
    "appId": "dyy.dongyuanwai",
    "copyright": "dyy.dongyuanwai © 2024",
    "compression": "maximum",
    "asar": true,
    "directories": {
      "output": "release/"
    },
    "nsis": {
      "oneClick": false,
      "allowToChangeInstallationDirectory": true,
      "perMachine": true,
      "deleteAppDataOnUninstall": true,
      "createDesktopShortcut": true,
      "createStartMenuShortcut": true,
      "shortcutName": "ElectronDeskTopTool"
    },
    "win": {
      "icon": "./public/login1.png",
      "artifactName": "${productName}-v${version}-${platform}-setup.${ext}",
      "target": [
        {
          "target": "nsis"
        }
      ]
    },
    "mac": {
      "icon": "./public/login1.png",
      "artifactName": "${productName}-v${version}-${platform}-setup.${ext}"
    },
    "linux": {
      "icon": "./public/login1.png",
      "artifactName": "${productName}-v${version}-${platform}-setup.${ext}"
    }
  },
  "dependencies": {
    "vue": "^3.5.12",
    "vue-router": "^4.4.5"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.1.4",
    "electron": "^30.0.0",
    "electron-builder": "^24.13.3",
    "electron-devtools-installer": "^3.2.0",
    "typescript": "~5.6.2",
    "vite": "^5.4.10",
    "vite-plugin-electron": "^0.28.4",
    "vue-tsc": "^2.1.8"
  }
}

 代码仓库:https://github.com/ssszjh/electron-vue3

 

标签:vue,plugin,electron,模板,vue3,main,true,vite
From: https://www.cnblogs.com/ssszjh/p/18569404

相关文章

  • 【C++11】可变参数模板/新的类功能/lambda/包装器--C++
    文章目录一、可变参数模板1、基本语法及原理2、包扩展3、empalce系列接口二、新的类功能1、默认的移动构造和移动赋值2、成员变量声明时给缺省值3、defult和delete4、final与override三、STL中一些变化四、lambda1、lambda表达式语法2、捕捉列表3、lambda的应用4、lamb......
  • VUE|学习笔记②(Vue3核心语法)
     目录OptionsAPI与CompositionAPIsetup概述setup的返回值setup与OptionsAPIsetup语法糖expor报错:应为声明或语句。ts(1128)ref创建:基本类型的响应式数据reactive创建:对象类型的响应式数据ref创建:对象类型的响应式数据ref对比reactivetoRefs与toRef computed......
  • FHQ-treap模板
    可以再加一个struct把整个树封装起来。。跟oiwiki学的#include<bits/stdc++.h>usingnamespacestd;#include<bits/stdc++.h>usingnamespacestd;structNode{Node*ch[2];intval,prio,cnt,siz;Node(int_val):val(_val),cnt(1),siz(1){......
  • Vue3.0 实操学习笔记
    安装 node.js安装 https://nodejs.org/en安装后执行node-v查看是否有异常以及npm-v查看是否异常调整为淘宝镜像,cnpm-v查看是否异常npminstall-gcnpm--registry=https://registry.npm.taobao.orgVue安装以及安装脚手架 vue-V查看是否异常cnpmi-......
  • (系列十二)Vue3+.Net8实现用户登录(超详细登录文档)
    说明  该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发)。   该系统文章,我会尽量说的非常详细,做到不管新手、老手都能看懂。   说明:OverallAuth2.0是一个简单、易懂、功能强大的权限+可视化流程管理系统。友情提醒:本篇文章是属于系......
  • 实验4 类的组合、继承、模板类、标准库
    实验任务2:代码:GradeCalc.hpp1#include<iostream>2#include<vector>3#include<string>4#include<algorithm>5#include<numeric>6#include<iomanip>78usingstd::vector;9usingstd::string;10......
  • Vue3+Typescript+Axios+.NetCore实现导出Excel文件功能
    前端代码//导出ExcelconstexportMaintenanceOrderSettlementItemExcelClick=async()=>{leturl=`${VITE_APP_API_URL}/api/app/maintenance/settlement-service-item/${currentMaintenanceOrderId.value}/${currentMaintenanceOrderSettlementRow.value.id}`;......
  • 实验四 类的组合、继承、模板类、标准库
    1、实验任务二GradeCalc.hpp#include<iostream>#include<vector>#include<string>#include<algorithm>#include<numeric>#include<iomanip>usingstd::vector;usingstd::string;usingstd::cin;usingstd::cout;usingstd......
  • vue3搭建成功后的一些简单配置
     vue3搭建成功后的一些简单配置 1.浏览器增加扩展插件“Vue.jsdevtools”极简插件:https://chrome.zzzmh.cn/搜索vue(建议再装一个json展示格式化插件)  2.下载vscode官网:https://code.visualstudio.com/Download安装好后,将......
  • 实验4 类的组合、继承、模板类、标准库
    实验任务2GradeCalc.hpp源码#include<iostream>#include<vector>#include<string>#include<algorithm>#include<numeric>#include<iomanip>usingstd::vector;usingstd::string;usingstd::cin;usingstd::cout;usingstd:......