-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.tauri.ts
More file actions
135 lines (127 loc) · 4.77 KB
/
vite.config.tauri.ts
File metadata and controls
135 lines (127 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/// <reference types="vite/client" />
/// <reference types="./src/vite-env.d.ts" />
import path from 'node:path'
import { UserConfig, defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import pkg from './package.json'
import fs from 'node:fs';
// https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
// @ts-ignor
export default defineConfig(async ({ command }): Promise<UserConfig> => {
const isServe = command === 'serve'
const isBuild = command === 'build'
const sourcemap = isServe || !!process.env.VSCODE_DEBUG
return {
resolve: {
alias: {
'@': path.join(__dirname, 'src'),
'@shared': path.join(__dirname, 'shared')
},
},
plugins: [react()],
// prevent vite from obscuring rust errors
clearScreen: false,
// Tauri expects a fixed port, fail if that port is not available
// server: {
// strictPort: true,
// },
// to access the Tauri environment variables set by the CLI with information about the current target
envPrefix: ['VITE_', 'TAURI_PLATFORM', 'TAURI_ARCH', 'TAURI_FAMILY', 'TAURI_PLATFORM_VERSION', 'TAURI_PLATFORM_TYPE', 'TAURI_DEBUG'],
build: {
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
target: process.env.TAURI_PLATFORM == 'windows' ? 'chrome105' : 'safari13',
// don't minify for debug builds
minify: !process.env.TAURI_DEBUG ? 'esbuild' : false,
// 为调试构建生成源代码映射 (sourcemap)
sourcemap: !!process.env.TAURI_DEBUG,
chunkSizeWarningLimit: 1000, // 将警告限制提高到1000KB
assetsInlineLimit: 0, // 确保文件不会被内联
// assetsDir: 'assets/i18n', // 指定输出目录
copyPublicDir: false,
rollupOptions: {
output: {
manualChunks: {
'i18n': ['i18next', 'react-i18next'],
'vditor': ['vditor'],
}
},
plugins: [
{
name: 'copy-i18n-files',
generateBundle() {
// 递归复制整个vditor文件夹
const copyDir = (dir, relativePath = '') => {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
const outputPath = path.join('vditor', relativePath, file);
if (stats.isFile()) {
this.emitFile({
type: 'asset',
fileName: outputPath,
source: fs.readFileSync(filePath)
});
} else if (stats.isDirectory()) {
copyDir(filePath, path.join(relativePath, file));
}
});
};
copyDir('node_modules/vditor/dist', 'dist');
}
}
]
}
},
server: process.env.VSCODE_DEBUG ? (() => {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
return {
host: url.hostname,
port: +url.port,
build: {
chunkSizeWarningLimit: 1000, // 将警告限制提高到1000KB
assetsInlineLimit: 0, // 确保文件不会被内联
assetsDir: 'assets/i18n', // 指定输出目录
copyPublicDir: false,
rollupOptions: {
output: {
manualChunks: {
// 手动拆分大依赖包
'i18n': ['i18next', 'react-i18next'],
'vditor': ['vditor'],
'radix-ui': [/@radix-ui/]
}
},
plugins: [
{
name: 'copy-i18n-files',
generateBundle() {
// 递归复制整个vditor文件夹
const copyDir = (dir, relativePath = '') => {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
const outputPath = path.join('vditor', relativePath, file);
if (stats.isFile()) {
this.emitFile({
type: 'asset',
fileName: outputPath,
source: fs.readFileSync(filePath)
});
} else if (stats.isDirectory()) {
copyDir(filePath, path.join(relativePath, file));
}
});
};
copyDir('node_modules/vditor/dist', 'dist');
}
}
]
}
}
}
})() : undefined,
}
})