20 changed files with 492 additions and 447 deletions
@ -1,70 +0,0 @@ |
|||||
/** |
|
||||
* electron 打包 |
|
||||
*/ |
|
||||
|
|
||||
import { join } from "path" |
|
||||
import { exec, spawn, ChildProcess } from "child_process" |
|
||||
import { watch, rollup, OutputOptions } from "rollup" |
|
||||
import electron from "electron" |
|
||||
import { waitOn } from "./utils" |
|
||||
import options from "./rollup.config" |
|
||||
import { main } from "../package.json" |
|
||||
const ora = require("ora") |
|
||||
const dotenv = require("dotenv") |
|
||||
const chalk = require("chalk") |
|
||||
const minimist = require("minimist") |
|
||||
|
|
||||
dotenv.config({ path: join(__dirname, "../.env") }) |
|
||||
const argv = minimist(process.argv.slice(2)) |
|
||||
const opts = options(argv.env) |
|
||||
const TAG = "[build-main.ts]" |
|
||||
const spinner = ora(`${TAG} Electron build...`) |
|
||||
|
|
||||
|
|
||||
|
|
||||
if (argv.watch) { |
|
||||
waitOn({ port: process.env.PORT as string }).then(msg => { |
|
||||
const watcher = watch(opts) |
|
||||
let child: ChildProcess | null |
|
||||
let manualRestart = false |
|
||||
watcher.on("change", filename => { |
|
||||
const log = chalk.green(`change -- ${filename}`) |
|
||||
console.log(TAG, log) |
|
||||
}) |
|
||||
watcher.on("event", ev => { |
|
||||
if (ev.code === "END") { |
|
||||
if (child && child.kill) { |
|
||||
console.log(child.pid) |
|
||||
manualRestart = true |
|
||||
// <number>child.pid
|
|
||||
// child.kill()
|
|
||||
process.kill( <number>child.pid) |
|
||||
child = null |
|
||||
setTimeout(() => { |
|
||||
manualRestart = false |
|
||||
}, 5000) |
|
||||
} |
|
||||
child = exec(`electron-forge start --inspect-electron --app-path ${join(__dirname, `../${main}`)}`, { |
|
||||
env: Object.assign(process.env, { NODE_ENV: argv.env }), |
|
||||
}) |
|
||||
child.on("close", () => { |
|
||||
if (!manualRestart) process.exit() |
|
||||
}) |
|
||||
} else if (ev.code === "ERROR") { |
|
||||
console.log(ev.error) |
|
||||
} |
|
||||
}) |
|
||||
}) |
|
||||
} else { |
|
||||
spinner.start() |
|
||||
rollup(opts) |
|
||||
.then(build => { |
|
||||
spinner.stop() |
|
||||
console.log(TAG, chalk.green("Electron build successed.")) |
|
||||
build.write(opts.output as OutputOptions) |
|
||||
}) |
|
||||
.catch(error => { |
|
||||
spinner.stop() |
|
||||
console.log(`\n${TAG} ${chalk.red("构建报错")}\n`, error, "\n") |
|
||||
}) |
|
||||
} |
|
@ -0,0 +1,102 @@ |
|||||
|
// @ts-nocheck
|
||||
|
|
||||
|
import { main } from "../package.json" |
||||
|
import { join } from "path" |
||||
|
import * as electron from "electron" |
||||
|
import * as dotenv from "dotenv" |
||||
|
import * as ora from "ora" |
||||
|
import * as chalk from "chalk" |
||||
|
import * as minimist from "minimist" |
||||
|
|
||||
|
import { exec, spawn, ChildProcess } from "child_process" |
||||
|
import { watch, rollup, OutputOptions } from "rollup" |
||||
|
import { waitOn } from "./utils" |
||||
|
import options from "./rollup.config" |
||||
|
// 注入环境变量
|
||||
|
dotenv.config({ path: join(__dirname, "../.env") }) |
||||
|
// 解析命令行参数
|
||||
|
const argv = minimist(process.argv.slice(2)) |
||||
|
// rollup配置
|
||||
|
const opts = options(argv.env) |
||||
|
const TAG = "[build-main.ts]" |
||||
|
// 加载图
|
||||
|
const spinner = ora(`${TAG} Electron build...`) |
||||
|
|
||||
|
function buildVite() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
let viteProcess = spawn("node", [join(__dirname, "../node_modules/vite/bin/vite.js"), "build"], { |
||||
|
stdio: "pipe", |
||||
|
env: Object.assign(process.env, { NODE_ENV: argv.env }), |
||||
|
}) |
||||
|
if (viteProcess) { |
||||
|
viteProcess.stdout.on("end", data => { |
||||
|
console.log(`\n[vite build end]`) |
||||
|
resolve(viteProcess) |
||||
|
}) |
||||
|
viteProcess.stderr.on("data", data => { |
||||
|
console.error(`\n[vite build err]: ${data}`) |
||||
|
reject() |
||||
|
}) |
||||
|
} else { |
||||
|
reject() |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
function tscCheck() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
let tscProcess = spawn("node", [join(__dirname, "../node_modules/typescript/bin/tsc")], { |
||||
|
stdio: "pipe", |
||||
|
env: Object.assign(process.env, { NODE_ENV: argv.env }), |
||||
|
}) |
||||
|
if (tscProcess) { |
||||
|
tscProcess.stdout.on("end", data => { |
||||
|
console.log(`[tsc check end]`) |
||||
|
resolve(tscProcess) |
||||
|
}) |
||||
|
tscProcess.stderr.on("data", data => { |
||||
|
console.error(`[tsc check err]: ${data}`) |
||||
|
reject() |
||||
|
}) |
||||
|
} else { |
||||
|
reject() |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
async function buildMain() { |
||||
|
try { |
||||
|
const build = await rollup(opts) |
||||
|
build.write(opts.output as OutputOptions) |
||||
|
} catch (error) { |
||||
|
console.log(`\n${TAG} ${chalk.red("构建报错")}\n`, error, "\n") |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function buildElectron() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
let tscProcess = spawn("node", [join(__dirname, "../node_modules/@electron-forge/cli/dist/electron-forge.js"), "make"], { |
||||
|
stdio: "pipe", |
||||
|
env: Object.assign(process.env, { NODE_ENV: argv.env }), |
||||
|
}) |
||||
|
if (tscProcess) { |
||||
|
tscProcess.stdout.on("data", data => { |
||||
|
console.log(`[electron build]: ${data}`) |
||||
|
}) |
||||
|
tscProcess.stdout.on("end", data => { |
||||
|
console.log(`[electron build end]`) |
||||
|
resolve(tscProcess) |
||||
|
}) |
||||
|
tscProcess.stderr.on("data", data => { |
||||
|
console.error(`[electron build err]: ${data}`) |
||||
|
reject() |
||||
|
}) |
||||
|
} else { |
||||
|
reject() |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
;(async () => { |
||||
|
await tscCheck() |
||||
|
await buildVite() |
||||
|
await buildMain() |
||||
|
// await buildElectron()
|
||||
|
})() |
@ -0,0 +1,111 @@ |
|||||
|
// @ts-nocheck
|
||||
|
|
||||
|
import { main } from "../package.json" |
||||
|
import { join } from "path" |
||||
|
import * as electron from "electron" |
||||
|
import * as dotenv from "dotenv" |
||||
|
import * as ora from "ora" |
||||
|
import * as chalk from "chalk" |
||||
|
import * as minimist from "minimist" |
||||
|
|
||||
|
import { exec, spawn, ChildProcess } from "child_process" |
||||
|
import { watch, rollup, OutputOptions } from "rollup" |
||||
|
import { waitOn } from "./utils" |
||||
|
import options from "./rollup.config" |
||||
|
// 注入环境变量
|
||||
|
dotenv.config({ path: join(__dirname, "../.env") }) |
||||
|
// 解析命令行参数
|
||||
|
const argv = minimist(process.argv.slice(2)) |
||||
|
// rollup配置
|
||||
|
const opts = options(argv.env) |
||||
|
const TAG = "[build-main.ts]" |
||||
|
// 加载图
|
||||
|
const spinner = ora(`${TAG} Electron build...`) |
||||
|
console.log(join(__dirname, "../node_modules/.bin/vite")) |
||||
|
|
||||
|
function runVite() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
let viteProcess = spawn("node", [`D:/1XYX/pro/vite-electron/node_modules/vite/bin/vite.js`], { |
||||
|
stdio: "pipe", |
||||
|
env: Object.assign(process.env, { NODE_ENV: argv.env }), |
||||
|
}) |
||||
|
if (viteProcess) { |
||||
|
let isReady = false |
||||
|
viteProcess.stdout.on("data", data => { |
||||
|
// console.log(`${data}`)
|
||||
|
if (!isReady && data.indexOf("ready") != -1) { |
||||
|
resolve(viteProcess) |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
viteProcess.stderr.on("data", data => { |
||||
|
console.error(`[vite err]: ${data}`) |
||||
|
reject() |
||||
|
}) |
||||
|
|
||||
|
viteProcess.on("close", code => { |
||||
|
console.log(`[vite close]: exited with code ${code}`) |
||||
|
reject() |
||||
|
}) |
||||
|
} else { |
||||
|
reject() |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
function runElectron() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
let electronProcess = spawn(electron as unknown as string, [join(__dirname, `../${main}`)], { |
||||
|
stdio: "pipe", |
||||
|
env: Object.assign(process.env, { NODE_ENV: argv.env }), |
||||
|
}) |
||||
|
if (electronProcess) { |
||||
|
resolve(electronProcess) |
||||
|
} else { |
||||
|
reject() |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
;(async () => { |
||||
|
let vitePorcess = await runVite() |
||||
|
console.log('[vite]', chalk.green(`vite ready.`)) |
||||
|
|
||||
|
const watcher = watch(opts) |
||||
|
let child: ChildProcess | null |
||||
|
let manualRestart = false |
||||
|
watcher.on("change", filename => { |
||||
|
const log = chalk.green(`change -- ${filename}`) |
||||
|
console.log(TAG, log) |
||||
|
}) |
||||
|
watcher.on("event",async ev => { |
||||
|
if (ev.code === "END") { |
||||
|
if (child && child.kill) { |
||||
|
manualRestart = true |
||||
|
child.kill() |
||||
|
child = null |
||||
|
setTimeout(() => { |
||||
|
manualRestart = false |
||||
|
}, 5000) |
||||
|
} |
||||
|
try { |
||||
|
child = await runElectron() |
||||
|
console.log('[electron]', chalk.green(`electron ready.`)) |
||||
|
child.on("close", () => { |
||||
|
if (!manualRestart) { |
||||
|
vitePorcess.kill() |
||||
|
child.kill() |
||||
|
process.exit() |
||||
|
} |
||||
|
}) |
||||
|
} catch (ev) { |
||||
|
console.log(ev.error) |
||||
|
vitePorcess.kill() |
||||
|
child.kill() |
||||
|
process.exit() |
||||
|
} |
||||
|
} else if (ev.code === "ERROR") { |
||||
|
console.log(ev.error) |
||||
|
} |
||||
|
}) |
||||
|
})() |
@ -1,4 +1,7 @@ |
|||||
/** |
/** |
||||
* !!! ensure process.cwd() correct |
* !!! ensure process.cwd() correct |
||||
*/ |
*/ |
||||
process.chdir(__dirname.slice(0, __dirname.lastIndexOf('dist'))) |
process.chdir(__dirname.slice(0, __dirname.lastIndexOf('dist'))) |
||||
|
|
||||
|
|
||||
|
export {}; |
@ -1,36 +1,31 @@ |
|||||
/** |
/** |
||||
* electron 主文件 |
* electron 主文件 |
||||
*/ |
*/ |
||||
console.log('2222'); |
import "@src/common/patch" |
||||
import '@src/common/patch' |
import * as dotenv from "dotenv" |
||||
const {join} = require("path") |
const { join } = require("path") |
||||
const {app,BrowserWindow} = require("electron") |
dotenv.config({ path: join(__dirname, "../../.env") }) |
||||
const dotenv = require("dotenv") |
const { app, BrowserWindow } = require("electron") |
||||
|
|
||||
dotenv.config({ path: join(__dirname, '../../../.env') }) |
let win |
||||
|
|
||||
let win |
function createWin() { |
||||
|
// 创建浏览器窗口dsa
|
||||
|
win = new BrowserWindow({ |
||||
|
width: 1024, |
||||
|
height: 768, |
||||
|
webPreferences: { |
||||
|
nodeIntegration: true, |
||||
|
contextIsolation: false, |
||||
|
preload: join(__dirname, "../../src/preload/index.js"), |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
console.log('1232asd啊2aasdaaaa'); |
const URL = app.isPackaged |
||||
|
? `file://${join(__dirname, "./index.html")}` // vite 构建后的静态文件地址
|
||||
|
: `http://localhost:${process.env.PORT}/#/login` // vite 启动的服务器地址
|
||||
|
|
||||
function createWin() { |
win?.loadURL(URL) |
||||
console.log('萨达'); |
} |
||||
// 创建浏览器窗口
|
|
||||
win = new BrowserWindow({ |
|
||||
width: 1024, |
|
||||
height: 768, |
|
||||
webPreferences: { |
|
||||
nodeIntegration: true, |
|
||||
contextIsolation: false, |
|
||||
preload: join(__dirname, '../../src/preload/index.js'), |
|
||||
}, |
|
||||
}) |
|
||||
|
|
||||
const URL = app.isPackaged |
app.whenReady().then(createWin) |
||||
? `file://${join(__dirname, '../render/index.html')}` // vite 构建后的静态文件地址
|
|
||||
: `http://localhost:${process.env.PORT}/login` // vite 启动的服务器地址
|
|
||||
|
|
||||
win?.loadURL(URL) |
|
||||
} |
|
||||
|
|
||||
app.whenReady().then(createWin) |
|
||||
|
@ -1,86 +0,0 @@ |
|||||
import React, { useState } from "react" |
|
||||
|
|
||||
export default () => { |
|
||||
const title = "TESAaT" |
|
||||
const [leftMenuList, setLeftMenuList] = useState<any[]>([ |
|
||||
{ title: "首页", path: "/" }, |
|
||||
{ title: "角色", children: [{ title: "月儿", path: "/about" }] }, |
|
||||
]) |
|
||||
|
|
||||
const [rightMenuList, setRightMenuList] = useState<any[]>([ |
|
||||
{ |
|
||||
title: "登录/注册", |
|
||||
click: true, |
|
||||
}, |
|
||||
]) |
|
||||
|
|
||||
function onLeftClick(e: any, menu: any, allMenu: any) { |
|
||||
if (menu.click || !menu.path) { |
|
||||
e.preventDefault() |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
function onRightClick(e: any, menu: any, allMenu: any) { |
|
||||
if (menu.click || !menu.path) { |
|
||||
e.preventDefault() |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return ( |
|
||||
<div className=""> |
|
||||
<div className="shadow bg-white h-12 leading-12 fixed top-0 left-0 right-0"> |
|
||||
<div className="container h-full clearfix mx-auto"> |
|
||||
<div className="h-full float-left cursor-pointer text-size-25px flex items-center">{title}</div> |
|
||||
<ul className="h-full float-left ml-10"> |
|
||||
{leftMenuList.map((menu, index) => { |
|
||||
return ( |
|
||||
<li className="h-full float-left group relative" key={index}> |
|
||||
<a |
|
||||
href={menu.path ? menu.path : "#"} |
|
||||
onClick={e => onLeftClick(e, menu, leftMenuList)} |
|
||||
className="h-full px-5 hover:(bg-cool-gray-200 text-black) text-gray-400 text-size-14px flex items-center" |
|
||||
> |
|
||||
{menu.title} |
|
||||
</a> |
|
||||
{menu.children && menu.children.length && ( |
|
||||
<ul className="absolute overflow-hidden transition-all duration-150 max-h-0 group-hover:max-h-500px left-0 top-full shadow"> |
|
||||
{menu.children.map((subMenu: any, jndex: number) => { |
|
||||
return ( |
|
||||
<li key={jndex} className="float-left relative"> |
|
||||
<a |
|
||||
href={subMenu.path ? subMenu.path : "#"} |
|
||||
onClick={e => onLeftClick(e, subMenu, leftMenuList)} |
|
||||
className="h-12 px-5 hover:(bg-cool-gray-200 text-black) text-gray-400 text-size-14px flex items-center" |
|
||||
> |
|
||||
{subMenu.title} |
|
||||
</a> |
|
||||
</li> |
|
||||
) |
|
||||
})} |
|
||||
</ul> |
|
||||
)} |
|
||||
</li> |
|
||||
) |
|
||||
})} |
|
||||
</ul> |
|
||||
<ul className="float-right h-full"> |
|
||||
{rightMenuList.map((menu, index) => { |
|
||||
return ( |
|
||||
<li key={index} className="h-full float-left relative cursor-pointer"> |
|
||||
<a |
|
||||
href={menu.path ? menu.path : "#"} |
|
||||
className="h-full px-5 text-size-14px flex items-center" |
|
||||
onClick={e => onRightClick(e, menu, rightMenuList)} |
|
||||
> |
|
||||
{menu.title} |
|
||||
</a> |
|
||||
</li> |
|
||||
) |
|
||||
})} |
|
||||
</ul> |
|
||||
</div> |
|
||||
</div> |
|
||||
<div className="h-12"></div> |
|
||||
</div> |
|
||||
) |
|
||||
} |
|
@ -1,15 +0,0 @@ |
|||||
import { defineConfig } from "vite-plugin-windicss"; |
|
||||
function range(size, startAt = 1) { |
|
||||
return Array.from(Array(size).keys()).map((i) => i + startAt); |
|
||||
} |
|
||||
export default defineConfig({ |
|
||||
preflight: false, |
|
||||
safelist: [ |
|
||||
range(30).map((i) => `p-${i}`), // p-1 to p-3
|
|
||||
range(10).map((i) => `mt-${i}`), // mt-1 to mt-10
|
|
||||
], |
|
||||
extract: { |
|
||||
include: ['src/render/**/*.{vue,html,jsx,tsx}'], |
|
||||
exclude: ['node_modules', '.git'], |
|
||||
}, |
|
||||
}); |
|
Loading…
Reference in new issue