feat(deps): 添加tauri打包(遗留pnpm build:file打包好的文件跨域无法访问) #94

This commit is contained in:
log1997
2025-12-09 17:52:56 +08:00
parent 2f0e3ac05b
commit f5152da190
30 changed files with 5714 additions and 659 deletions

View File

@@ -25,7 +25,7 @@
"github-markdown-css": "^5.8.0",
"localforage": "^1.10.0",
"lodash-es": "^4.17.21",
"lucide-vue-next": "^0.555.0",
"lucide-vue-next": "^0.556.0",
"markdown-it": "^14.1.0",
"pinia": "^3.0.3",
"pinia-plugin-persist": "^1.0.0",
@@ -36,7 +36,7 @@
"vue": "^3.5.13",
"vue-dompurify-html": "^5.2.0",
"vue-draggable-plus": "^0.6.0",
"vue-i18n": "^11.1.12",
"vue-i18n": "^11.2.2",
"vue-router": "^4.5.0",
"vue-toast-notification": "^3",
"vue3-colorpicker": "^2.3.0",
@@ -51,25 +51,27 @@
"@iconify-json/fluent": "^1.2.8",
"@tailwindcss/typography": "^0.5.15",
"@tailwindcss/vite": "^4.1.13",
"@tauri-apps/cli": "^2.9.5",
"@testing-library/vue": "^8.1.0",
"@types/canvas-confetti": "^1.6.4",
"@types/lodash-es": "^4.17.12",
"@types/markdown-it": "^14.1.2",
"@types/node": "^24.5.2",
"@types/node": "^24.10.2",
"@types/three": "^0.166.0",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"@typescript-eslint/eslint-plugin": "^8.49.0",
"@typescript-eslint/parser": "^8.49.0",
"@vitejs/plugin-legacy": "^7.2.1",
"@vitejs/plugin-vue": "^6.0.1",
"@vitest/ui": "^4.0.15",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.8.1",
"autoprefixer": "^10.4.20",
"baseline-browser-mapping": "^2.8.32",
"daisyui": "^5.1.13",
"eslint": "^9.15.0",
"eslint-plugin-vue": "^10.4.0",
"globals": "^16.4.0",
"happy-dom": "^18.0.1",
"happy-dom": "^20.0.11",
"husky": "^9.1.7",
"jsdom": "^27.0.0",
"path": "^0.12.7",
@@ -77,18 +79,18 @@
"rollup-plugin-visualizer": "^6.0.3",
"sass": "^1.81.0",
"sass-loader": "^16.0.3",
"tailwindcss": "^4.1.13",
"tailwindcss": "^4.1.17",
"terser": "^5.36.0",
"typescript": "5.5.3",
"typescript": "~5.9.3",
"unplugin-auto-import": "^20.1.0",
"unplugin-icons": "^22.3.0",
"unplugin-vue-components": "^29.1.0",
"unplugin-vue-components": "^30.0.0",
"vite": "^7.1.6",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-inspect": "^11.3.3",
"vite-plugin-svg-icons": "^2.0.1",
"vite-plugin-vue-devtools": "^8.0.2",
"vitest": "^3.2.4",
"vitest": "^4.0.15",
"vue-tsc": "^3.0.7"
}
}

1205
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

4
src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/gen/schemas

5005
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

25
src-tauri/Cargo.toml Normal file
View File

@@ -0,0 +1,25 @@
[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.77.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2.5.3", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
log = "0.4"
tauri = { version = "2.9.4", features = ["devtools"] }
tauri-plugin-log = "2"

3
src-tauri/build.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View File

@@ -0,0 +1,11 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "enables the default permissions",
"windows": [
"main"
],
"permissions": [
"core:default"
]
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

16
src-tauri/src/lib.rs Normal file
View File

@@ -0,0 +1,16 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
app_lib::run();
}

37
src-tauri/tauri.conf.json Normal file
View File

@@ -0,0 +1,37 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "log-lottery",
"version": "0.1.0",
"identifier": "to2026.xyz",
"build": {
"frontendDist": "../dist",
"devUrl": "http://localhost:6719/log-lottery",
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build"
},
"app": {
"windows": [
{
"title": "log-lottery",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}

5
src/components.d.ts vendored
View File

@@ -1,8 +1,11 @@
/* eslint-disable */
// @ts-nocheck
// biome-ignore lint: disable
// oxlint-disable
// ------
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
// biome-ignore lint: disable
export {}
/* prettier-ignore */

View File

@@ -113,6 +113,10 @@ export const configRoutes = {
],
}
const routes = [
{
path: '/',
redirect: '/log-lottery',
},
{
path: '/log-lottery',
component: Layout,
@@ -135,7 +139,7 @@ const routes = [
const envMode = import.meta.env.MODE
const router = createRouter({
// 读取环境变量
history: envMode === 'file' ? createWebHashHistory() : createWebHistory(),
history: (envMode === 'file' || import.meta.env.TAURI_PLATFORM) ? createWebHashHistory() : createWebHistory(),
routes,
})

View File

@@ -1,6 +1,7 @@
import type { IPersonConfig, IPrizeConfig } from '@/types/storeType'
import dayjs from 'dayjs'
import { defineStore } from 'pinia'
import { v4 as uuidv4 } from 'uuid'
import { computed, ref, toRaw, watch } from 'vue'
import { IndexDb } from '@/utils/dexie'
import { defaultPersonList } from './data'
@@ -150,7 +151,10 @@ export const usePersonConfig = defineStore('person', () => {
personDb.deleteAll('alreadyPersonList')
}
function setDefaultPersonList() {
personConfig.value.allPersonList = defaultPersonList
personConfig.value.allPersonList = defaultPersonList.map((item: any) => {
item.uuid = uuidv4()
return item
})
personConfig.value.alreadyPersonList = []
personDb.setAllData('allPersonList', defaultPersonList)
personDb.deleteAll('alreadyPersonList')

View File

@@ -22,9 +22,8 @@ const process = require('node:process')
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, __dirname)
const chunkName = mode === 'prebuild' ? '[name]' : 'chunk'
return {
base: mode === 'file' ? './' : '/log-lottery/',
base: (mode === 'file' || process.env.TAURI_ENV_PLATFORM) ? './' : '/log-lottery/',
plugins: [
vue(),
tailwindcss(),
@@ -90,9 +89,15 @@ export default defineConfig(({ mode }) => {
// ]
// }
},
clearScreen: false,
server: {
host: 'localhost',
port: 6719,
strictPort: true,
watch: {
// 告诉 Vite 忽略监听 `src-tauri` 目录
ignored: ['**/src-tauri/**'],
},
proxy: {
'/api': {
target: env.VITE_BASE_URL,
@@ -103,13 +108,21 @@ export default defineConfig(({ mode }) => {
},
},
},
// 添加有关当前构建目标的额外前缀,使这些 CLI 设置的 Tauri 环境变量可以在客户端代码中访问
envPrefix: ['VITE_', 'TAURI_ENV_*'],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
build: {
minify: 'terser',
// Tauri 在 Windows 上使用 Chromium在 macOS 和 Linux 上使用 WebKit
// target: (process.env.TAURI_ENV_PLATFORM && mode !== 'file')
// ? (process.env.TAURI_ENV_PLATFORM === 'windows' ? 'chrome105' : 'safari13')
// : 'es2020', // 普通前端可使用更高版本 JS 支持
minify: process.env.TAURI_ENV_PLATFORM
? (!process.env.TAURI_ENV_DEBUG ? 'esbuild' : false)
: 'terser', // 普通构建推荐使用 terser 提供更强压缩选项
terserOptions: {
compress: {
// 生产环境时移除console
@@ -120,7 +133,7 @@ export default defineConfig(({ mode }) => {
// 关闭文件计算
reportCompressedSize: false,
// 关闭生成map文件 可以达到缩小打包体积
sourcemap: false, // 这个生产环境一定要关闭,不然打包的产物会很大
sourcemap: process.env.NODE_ENV === 'development' || !!process.env.TAURI_ENV_DEBUG, // 这个生产环境一定要关闭,不然打包的产物会很大
rollupOptions: {
output: {
chunkFileNames: `js/${chunkName}-[hash].js`, // 引入文件名的名称
@@ -144,6 +157,7 @@ export default defineConfig(({ mode }) => {
environment: 'jsdom',
// include: ['**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
// passWithNoTests: true,
testTimeout: 10000,
transformMode: {
web: [/\.[jt]sx$/],
},