Vite 搭配 Electron 整理(不使用TypeScript)
Vite 搭配 Electron 整理(不使用TypeScript)
- cawa-93/vite-electron-builder: Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla
- Vue3+Electron整合方式 - 知乎
目前好像沒有官方推薦的,不過我選方案一,因為官方有特別註明怎麼調回 JavaScript,我 TypeScript 還沒有學。Orz
調成 JavaScript
推薦看官網教學,也有可能因為時間更新而改變。
快速建置範本專案
Create a New Repository from cawa-93/vite-electron-builder
移除 JavaScript
In project root:
- Remove vetur.config.js
- Remove .github/workflows/typechecking.yml
- Remove types directory
- Remove tsconfig.json directory
In package.json
- Remove buildEnvTypes, pretypecheck and all typecheck* sctipts(我找不到…)
|
|
|
|
- Remove simple-git-hooks.pre-push and run npx simple-git-hooks to update git-hooks internal config
|
|
|
|
- Remove unnecessary dependencies by:
|
|
In .eslintrc.json Remove:
plugin:@typescript-eslint/recommended from extends
parser
parserOptions
@typescript-eslint from plugins
types/env.d.ts from ignorePatterns
All @typescript-eslint/* from rules
下面不要拿掉,不然git commit 會有錯誤(eslint 會報錯)
|
|
In packages/main:
Rewrite src/index.ts to src/index.js (改名)
In vite.config.js change build.lib.entry to src/index.js
Remove tsconfig.json
In packages/preload:
Rewrite src/index.ts to src/index.js
In vite.config.js change build.lib.entry to src/index.js
Remove tsconfig.json
Remove types directory
In packages/renderer:
Rewrite all files in src from TS to JS. If you want use Vue, you need remove lang="ts" attribute in all .vue files.
In index.html change script src attribute to you new entry file (it may be ./src/index.js for example).
Remove tsconfig.json
In .eslintrc.json remove parserOptions.parser
Remove types directory
ExtensionLoadWarning(無法解決)
|
|
|
|
|
|
彩蛋
調整 Electron 視窗資料,實用功能
如何实现 electron 窗体透明 transparent 效果?
transparent: true
拖移視窗
electron程序,自定义标题栏的几个特殊css属性总结
-webkit-app-region: drag;
- autoHideMenuBar:true
- frame:false
Frameless window with controls in electron (Windows) - Stack Overflow
electron - 无边框、最大化、最小化、等比缩放问题_wanzheng_96的博客-CSDN博客
javascript - Electron require() is not defined - Stack Overflow
Electron 12+ 出現 require is not defined 報錯解決_Jesse_0 - MdEditor
electron - 无边框、最大化、最小化、等比缩放问题 無法使用在最新版程式
|
|
後來發現會現行的 RENDER 會有種突,所以還是不要這樣用。
解決方式
main 程式寫 electron 程式碼
原Web 操作寫在 preload
HTML(App.vue)可以這樣呼叫 preload 程式
有空在寫仔細,就怕沒控整理。先簡單記錄