From 7e9770805b3584a779488f1f08e89faac30bc69c Mon Sep 17 00:00:00 2001 From: npmrun <62639956+npmrun@users.noreply.github.com> Date: Wed, 28 Jul 2021 02:11:00 +0800 Subject: [PATCH] bug fixed --- a.md | 5 ++++- src/main/index.ts | 3 ++- src/render/main.tsx | 5 +++++ src/render/plugins/electron/index.ts | 3 +++ src/render/views/Home/index.tsx | 6 +++--- vite.config.ts | 12 +++++++++--- 6 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/render/plugins/electron/index.ts diff --git a/a.md b/a.md index a2ea6bc..3999d12 100644 --- a/a.md +++ b/a.md @@ -4,4 +4,7 @@ https://www.jianshu.com/p/4699b825d285 // // 指定了就出不来了,官网的解释是:No need to specify which files to include in the app // "files": [ // "dist/electron/**/*" - // ], \ No newline at end of file + // ], + + + https://www.wyr.me/post/680 \ No newline at end of file diff --git a/src/main/index.ts b/src/main/index.ts index 1352182..62a522b 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -30,8 +30,9 @@ function createWin() { width: 1024, height: 768, webPreferences: { + // 下面两个必须这么用,看a.md的文档 nodeIntegration: true, - // contextIsolation: false, + contextIsolation: false, // preload: join(__dirname, "../../src/preload/index.js"), }, }) diff --git a/src/render/main.tsx b/src/render/main.tsx index c514cb2..78bf28b 100644 --- a/src/render/main.tsx +++ b/src/render/main.tsx @@ -5,8 +5,13 @@ import ReactDOM from "react-dom"; import "@/plugins/i18n" import {Provider} from 'react-redux' +import electron from "@/plugins/electron" + import Router from "./AppRouter"; +console.log(electron); + + ReactDOM.render( diff --git a/src/render/plugins/electron/index.ts b/src/render/plugins/electron/index.ts new file mode 100644 index 0000000..9d4b7e5 --- /dev/null +++ b/src/render/plugins/electron/index.ts @@ -0,0 +1,3 @@ +const electron = require("electron") // 只能用require + +export default electron diff --git a/src/render/views/Home/index.tsx b/src/render/views/Home/index.tsx index a86ca5f..969da62 100644 --- a/src/render/views/Home/index.tsx +++ b/src/render/views/Home/index.tsx @@ -24,9 +24,9 @@ function Home(props: HomeProps) { return (
- home
- about
- login
+ 首页
+ 关于
+ 登录
) } diff --git a/vite.config.ts b/vite.config.ts index 0749752..ba9a91f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,10 +2,15 @@ import { defineConfig } from "vite" import reactRefresh from "@vitejs/plugin-react-refresh" // import WindiCSS from "vite-plugin-windicss" const { resolve, join } = require("path") -// import electron from "vitejs-plugin-electron" +import electron from "vitejs-plugin-electron" import { minifyHtml, injectHtml } from "vite-plugin-html" -console.log(process.env.NO); +console.log(process.env.NO) + +let isDev = process.env.NODE_ENV === "development" + +let plugins = [] +// plugins.push(electron()) // https://vitejs.dev/config/ export default defineConfig({ @@ -38,8 +43,9 @@ export default defineConfig({ "@root": __dirname, }, }, - // electron() + // plugins: [ + ...plugins, reactRefresh(), minifyHtml(), injectHtml({