electron forge 初始化 vite ts vue3 项目模版

直接使用官方文档,肯定会掉进坑里,浪费不少时间。

切勿 升级 package.json 里面的依赖,否则可能会掉进 vitevue.runtime 的坑里,除非你下定决心彻底解决所有问题。

默认使用的 npm 装的依赖。

1

arduino 复制代码
# https://www.electronforge.io/templates/vite-+-typescript
npx create-electron-app@latest my-new-app --template=vite-typescript

# https://www.electronforge.io/guides/framework-integration/vue-3
npm install vue
npm install --save-dev @vitejs/plugin-vue

2 重命名 vite.renderer.config.tsvite.renderer.config.mts

修改 forge.config.ts 中的 renderer 配置: vite.renderer.config.tsvite.renderer.config.mts

javascript 复制代码
// vite.renderer.config.mts

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

// https://vitejs.dev/config
export default defineConfig({
  plugins: [vue()]
});

3 改动一下文件

html 复制代码
// index.html

<!doctype html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>Hello World!</title>
	</head>
	<body>
		<div id="app"></div>
		<script
			type="module"
			src="/src/renderer.ts"
		></script>
	</body>
</html>

创建 src/vue/App.vue

xml 复制代码
<template>
	<h1>💖 Hello World!</h1>
	<p>Welcome to your Electron application.</p>
</template>

<script setup>
console.log('👋 This message is being logged by "App.vue", included via Vite')
</script>

修改 src/renderer.ts

javascript 复制代码
import { createApp } from 'vue';
import './index.css';
import App from './vue/App.vue';

console.log(
  '👋 This message is being logged by "renderer.ts", included via Vite',
);

createApp(App).mount('#app');

启动项目和打包应该都是能正常运行的

arduino 复制代码
npm run start
npm run package
相关推荐
web打印社区12 小时前
浏览器静默打印?先别装第三个库了
前端·vue.js·chrome·electron·pdf
不可能片场18 小时前
Electron 退化成 node:一个环境变量的锅
前端·electron
不可能片场19 小时前
接口返回 200 不代表活着:catch-all 路由的陷阱
前端·electron
EatFan1 天前
Electron 构建你的第一个应用
electron
枫叶梨花2 天前
Electrobun透明窗口在Windows上的输入穿透排查
前端·electron·bun
xiaoyan20152 天前
2026最新款Electron41+React19+AntDesign电脑端后台管理系统Exe
react.js·electron·vite
会周易的程序员4 天前
告别 matiec 与 Docker:aiDgePLC Editor 全面拥抱 STVM 字节码编译
物联网·网关·electron·软plc·iec61131·stvm·open plc
Flynt6 天前
Chrome 修了个零日漏洞,你的 VS Code 和 Cursor 可能还在裸奔
安全·electron·visual studio code
星辰徐哥6 天前
鸿蒙PC平台 Gnote 笔记应用适配实战:从 Linux 到 鸿蒙PC 的 Electron 迁移
linux·笔记·electron·harmonyos·gnote
不可能片场7 天前
nohup 之后进程还是死了:GUI 子进程的存活陷阱
前端·electron