Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
zake-github committed Mar 19, 2024
0 parents commit 92cdc53
Show file tree
Hide file tree
Showing 29 changed files with 3,211 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# electron-app

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.

## Customize configuration

See [Vite Configuration Reference](https://vitejs.dev/config/).

## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

### Type-Check, Compile and Minify for Production

```sh
npm run build
```
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "electron-app",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build --force"
},
"dependencies": {
"vue": "^3.4.21"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.2",
"@types/node": "^20.11.25",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/tsconfig": "^0.5.1",
"electron": "^29.1.4",
"electron-build": "^0.0.3",
"npm-run-all2": "^6.1.2",
"typescript": "~5.4.0",
"vite": "^5.1.5",
"vue-tsc": "^2.0.6"
}
}
18 changes: 18 additions & 0 deletions plugins/vite.electron.build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 生产环境插件
import type { Plugin } from 'vite';

// vite 插件要求导出一个对象 有一个name属性

export const ElectronPlugins = (): Plugin => {
return {
name: 'electron-dev',
// 配置vite钩子
configureServer(server) {
server?.httpServer?.on('listening', () => {
const addressInfo = server.httpServer?.address()
console.log(addressInfo)
})

}
}
}
53 changes: 53 additions & 0 deletions plugins/vite.electron.dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 开发环境插件
import type { Plugin } from 'vite';
import type { AddressInfo } from 'net';
import { spawn } from 'child_process';
import fs from 'node:fs';

// vite 插件要求导出一个对象 有一个name属性
const buildBackground = () => {
require('esbuild').buildSync({
entryPoints: ['src/background.ts'],
bundle: true,
outfile: 'dist/background.js',
platform: 'node',
target: 'node16',
external: ['electron']
});
};
export const ElectronPlugins = (): Plugin => {
return {
name: 'electron-dev',
// 配置vite钩子
configureServer(server) {
buildBackground();
server?.httpServer?.on('listening', () => {
//读取vite服务信息
const addressInfo = server.httpServer?.address() as AddressInfo;
//拼接ip electron启动服务使用
const IP = `http://localhost:${addressInfo.port}`;
//第一个参数是electron入口文件
//require('electron')返回一个路径
//electron 需要把ts编译成js
//进程传参法发送给electron
//electron 0 'dist/background.js' 1 IP 2 参数顺序
let ElectronProcess = spawn(require('electron'), [
'dist/background.js',
IP
]);
fs.watchFile('src/background.ts', () => {
ElectronProcess.kill();
buildBackground();
ElectronProcess = spawn(require('electron'), [
'dist/background.js',
IP
]);
});
ElectronProcess.stderr.on('data', data => {
console.log('日志', data.toString());
});
console.log(IP);
});
}
};
};
Loading

0 comments on commit 92cdc53

Please sign in to comment.