forked from l1xnan/duckling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
91 lines (89 loc) · 2.76 KB
/
vite.config.ts
File metadata and controls
91 lines (89 loc) · 2.76 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
/// <reference types="vitest/config" />
import path from 'path';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import jotaiDebugLabel from 'jotai/babel/plugin-debug-label';
import jotaiReactRefresh from 'jotai/babel/plugin-react-refresh';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
tailwindcss(),
react({
babel: {
presets: ['jotai/babel/preset'],
plugins: [jotaiDebugLabel, jotaiReactRefresh],
},
}),
viteStaticCopy({
targets: [
{
src: 'node_modules/web-tree-sitter/tree-sitter.wasm',
dest: '',
},
],
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@tabler/icons-react': '@tabler/icons-react/dist/esm/icons/index.mjs',
},
},
test: {
// Vitest configuration options
globals: true, // Use global APIs like describe, it, expect
environment: 'node', // Important for tree-sitter which needs Node APIs
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 5173,
strictPort: true,
},
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ['VITE_', 'TAURI_'],
build: {
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
target:
process.env.TAURI_ENV_PLATFORM == 'windows' ? 'chrome105' : 'safari15',
// don't minify for debug builds
minify: !process.env.TAURI_ENV_DEBUG ? 'esbuild' : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_ENV_DEBUG,
rollupOptions: {
output: {
// 动态覆盖 WASM 文件规则
assetFileNames: (assetInfo) => {
const isWasm = assetInfo.names?.[0]?.endsWith('.wasm');
return isWasm
? 'assets/[name].[ext]' // WASM 无哈希
: 'assets/[name]-[hash].[ext]'; // 其他文件带哈希
},
// manualChunks: {
// 'web-tree-sitter': ['web-tree-sitter'],
// },
codeSplitting: {
groups: [
// 将 web-tree-sitter 单独打包为一个 chunk
{ name: 'web-tree-sitter', test: /node_modules\/web-tree-sitter/ },
],
},
},
external: (id) => {
if (id.startsWith('@shikijs/langs')) {
return !id.includes('json') && !id.includes('sql');
}
return false;
},
},
},
worker: {
format: 'es',
},
});