Browse Source

增加热更新,修改框架

Caner 2 years ago
parent
commit
81a610cee8
15 changed files with 376 additions and 283 deletions
  1. 2 1
      .eslintignore
  2. 5 26
      .eslintrc.json
  3. 3 1
      .gitignore
  4. 8 8
      electron/main.js
  5. 1 1
      electron/preload.js
  6. 0 0
      env.d.ts
  7. 11 14
      package.json
  8. 1 1
      src/App.vue
  9. 2 1
      src/components/icon.vue
  10. 1 1
      src/main.ts
  11. 1 1
      src/services/rem.ts
  12. 1 1
      src/views/index/route.ts
  13. 21 23
      tsconfig.json
  14. 4 0
      vite.config.ts
  15. 315 204
      yarn.lock

+ 2 - 1
.eslintignore

@@ -1,4 +1,5 @@
 # 排除eslint检查文件
 /dist
 /public
-/main.js
+/dist-electron
+/electron

+ 5 - 26
.eslintrc.json

@@ -29,36 +29,15 @@
     "linebreak-style": [ 0, "error", "windows" ],
     "import/no-unresolved": 0,
     "import/extensions": 0,
-    "import/no-absolute-path": 0,
-    "import/no-extraneous-dependencies": 2,
-    "class-methods-use-this": 0,
-    "no-mixed-operators": 0,
-    "eol-last": 0,
-    "import/newline-after-import": 0,
     "vue/multi-word-component-names": 0,
     "no-param-reassign": 0,
-    "no-restricted-syntax": 0,
-    "no-underscore-dangle": 0,
     "no-plusplus": 0,
-    "no-bitwise": 0,
-    "guard-for-in": 0,
-    "func-names": 0,
-    "import/order": 0,
-    "vue/no-deprecated-slot-attribute": 0,
     "vue/v-on-event-hyphenation": 0,
-    "vue/no-deprecated-filter": 0,
-    "vue/require-explicit-emits": 0,
-    "vue/no-v-html": 0,
-    "vue/order-in-components": 0,
-    "vue/no-reserved-component-names": 0,
     "no-promise-executor-return": 0,
-    "no-sparse-arrays": 0,
-    "no-nested-ternary": 0,
-    "no-continue": 0,
-    "complexity": [ 2, 9 ],
-    "no-return-await": 0,
-    "max-classes-per-file": 0,
-    "consistent-return" : 0,
-    "no-shadow": 0
+    "no-shadow": 0,
+    "prefer-destructuring": 0,
+    "no-new": 0,
+    "func-names": 0,
+    "no-nested-ternary": 0
   }
 }

+ 3 - 1
.gitignore

@@ -25,4 +25,6 @@ dist-ssr
 yarn.lock
 dist
 package-lock.json
-dist-ssr
+dist-ssr
+dist-electron
+out

+ 8 - 8
main.js → electron/main.js

@@ -1,9 +1,9 @@
-const {
-  app, BrowserWindow, Menu, ipcMain,globalShortcut
-} = require('electron')// 引入electron
+const { app, BrowserWindow, Menu, ipcMain, globalShortcut, dialog, shell } = require('electron');
 const path = require('path')
-let win; let
-  loadingWin
+const { createWriteStream, existsSync } = require('fs');
+const request = require('request');
+
+let win, loadingWin;
 Menu.setApplicationMenu(null) // 去掉菜单栏
 app.commandLine.appendSwitch('wm-window-animations-disabled') // 拖动闪屏
 
@@ -30,7 +30,7 @@ async function downloadFile(url) {
 
   // FN1
   const res = await new Promise((res, rej) => {
-    const stream = request(url).pipe(fs.createWriteStream(filePath))
+    const stream = request(url).pipe(createWriteStream(filePath))
     stream.on('finish', res(true))
     stream.on('error', rej(false))
   })
@@ -39,7 +39,7 @@ async function downloadFile(url) {
 
 /** 打开文件夹 */
 function openFileInFolder(path) {
-  if (!fs.existsSync(path)) return false
+  if (!existsSync(path)) return false
   shell.showItemInFolder(path)
   return true
 }
@@ -69,7 +69,7 @@ const createWindow = () => {
       contextIsolation: true,
       nodeIntegration: true,
       webSecurity: false,
-      preload: path.join(__dirname, 'preload.js')
+      preload: path.join(__dirname, './preload.js')
     },
     show: false
   })// 创建一个窗口

+ 1 - 1
preload.js → electron/preload.js

@@ -1,4 +1,4 @@
-const { contextBridge, ipcRenderer } = require('electron')
+const { contextBridge, ipcRenderer } = require('electron');
 
 contextBridge.exposeInMainWorld('$electron', {
   send: (channel, args) => ipcRenderer.send(channel, args),

+ 0 - 0
src/vite-env.d.ts → env.d.ts


+ 11 - 14
package.json

@@ -1,20 +1,16 @@
 {
-  "name": "contrl-client",
+  "name": "demo",
   "version": "1.0.0",
-  "main": "main.js",
+  "main": "electron/main.js",
   "author": "Caner",
-  "description": "控制端",
+  "description": "one electron vite vue demo",
   "scripts": {
-    "dev": "concurrently -k \"yarn:dev_*\"",
+    "dev": "vite",
     "build": "vue-tsc --noEmit && vite build && yarn pmake",
-    "dev_vite": "vite",
-    "dev_electron": "electron .",
     "make": "electron-forge make",
     "pmake": "electron-forge package"
   },
   "dependencies": {
-    "echarts": "^5.4.2",
-    "socket.io-client": "^4.6.1",
     "vue": "^3.3.2",
     "vue-router": "^4.2.0"
   },
@@ -24,25 +20,26 @@
     "@types/node": "^18.15.3",
     "@typescript-eslint/parser": "^5.40.0",
     "@vitejs/plugin-vue": "^4.2.3",
+    "electron": "^23.1.2",
     "eslint": "^8.40.0",
     "eslint-config-airbnb-base": "^15.0.0",
     "eslint-plugin-import": "^2.27.5",
     "eslint-plugin-vue": "^9.13.0",
-    "concurrently": "^8.1.0",
-    "less": "^4.1.3",
-    "typescript": "^5.0.4",
+    "request": "^2.88.2",
+    "sass": "^1.63.3",
+    "typescript": "~5.0.4",
     "vite": "^4.3.6",
     "vite-plugin-compression": "^0.5.1",
+    "vite-plugin-electron": "^0.11.2",
     "vite-plugin-eslint": "^1.8.1",
-    "vue-tsc": "^1.6.5",
     "vite-plugin-svg-icons": "^2.0.1",
-    "electron": "^23.1.2"
+    "vue-tsc": "^1.6.5"
   },
   "config": {
     "forge": {
       "packagerConfig": {
         "asar": true,
-        "ignore": "(out|vite.config.ts|README.md|.env|.gitignore|.eslintrc.json|src|public|node_modules|package-lock.json)"
+        "ignore": "(dist-electron|out|vite.config.ts|README.md|.env|.gitignore|.eslintrc.json|src|public|node_modules|package-lock.json)"
       },
       "makers": [
         {

+ 1 - 1
src/App.vue

@@ -11,4 +11,4 @@ onMounted(() => {
     electron.send('close-loading')
   }
 })
-</script>
+</script>

+ 2 - 1
src/components/icon.vue

@@ -1,5 +1,6 @@
 <script setup lang="ts">
 import { computed } from 'vue'
+
 const props = defineProps<{
   name: string,
   size?: number,
@@ -22,4 +23,4 @@ const newSize = computed(() => `${props.size ?? 16}`)
       :fill="newColor"
     />
   </svg>
-</template>
+</template>

+ 1 - 1
src/main.ts

@@ -1,6 +1,6 @@
 import { createApp } from 'vue'
-import App from './App.vue'
 import { createRouter, RouteRecordRaw, createWebHistory } from 'vue-router'
+import App from './App.vue'
 import Icon from '@/components/icon.vue'
 import 'virtual:svg-icons-register'
 import '@/services/rem'

+ 1 - 1
src/services/rem.ts

@@ -16,4 +16,4 @@
   if (!doc.addEventListener) { return }
   win.addEventListener(resizeEvt, recalc, false)
   console.log('rem自适应')
-}(document, window))
+}(document, window))

+ 1 - 1
src/views/index/route.ts

@@ -6,4 +6,4 @@ export default {
     authorize: true
   },
   component: home
-}
+}

+ 21 - 23
tsconfig.json

@@ -1,30 +1,28 @@
 {
   "compilerOptions": {
-    "target": "ESNext",
-    "useDefineForClassFields": true,
-    "experimentalDecorators": true,
-    "module": "ESNext",
-    "moduleResolution": "Node",
-    "strict": true,
-    "jsx": "preserve",
-    "sourceMap": true,
-    "resolveJsonModule": true,
-    "isolatedModules": true,
-    "esModuleInterop": true,
-    "lib": [
-      "ESNext",
-      "DOM"
-    ],
-    "skipLibCheck": true,
-    "baseUrl": "./",
-    "paths": {
-      "@/*": [
-        "src/*"
-      ]
-    },
-    "types": ["vite-plugin-svg-icons/client"]
+      "target": "ES2020",
+      "useDefineForClassFields": true,
+      "module": "ESNext",
+      "lib": ["ES2020", "DOM", "DOM.Iterable"],
+      "skipLibCheck": true,
+  
+      /* Bundler mode */
+      "moduleResolution": "bundler",
+      "allowImportingTsExtensions": true,
+      "resolveJsonModule": true,
+      "isolatedModules": true,
+      "noEmit": true,
+      "jsx": "preserve",
+  
+      /* Linting */
+      "strict": true,
+      "noUnusedLocals": true,
+      "noUnusedParameters": true,
+      "noFallthroughCasesInSwitch": true,
+      "types": ["vite-plugin-svg-icons/client"]
   },
   "include": [
+    "*.d.ts",
     "src/**/*.ts",
     "src/**/*.d.ts",
     "src/**/*.tsx",

+ 4 - 0
vite.config.ts

@@ -4,6 +4,7 @@ import eslint from 'vite-plugin-eslint'
 import viteCompression from 'vite-plugin-compression'
 import { resolve } from 'path'
 import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
+import electron from 'vite-plugin-electron'
 
 export default () => defineConfig({
   base: './',
@@ -21,6 +22,9 @@ export default () => defineConfig({
       // Specify symbolId format
       symbolId: 'icon-[dir]-[name]'
     }),
+    electron({
+      entry: 'electron/main.js',
+    }),
   ],
   server: {
     host: '0.0.0.0',

File diff suppressed because it is too large
+ 315 - 204
yarn.lock


Some files were not shown because too many files changed in this diff