-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
127 lines (110 loc) · 2.86 KB
/
vite.config.ts
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
import { defineConfig, Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import jsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
// @ts-ignore
import importmap from 'vite-plugin-importmap'
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { TDesignResolver } from 'unplugin-vue-components/resolvers';
import { NAMESPACE } from './src/constants'
import { join } from 'node:path';
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
const importmapMark = process.env.VITE_BUILD_TYPE
export default defineConfig({
base: './',
plugins: [
importmap(importmapMark),
initDataFiles(),
createIndexHtml(),
vue(),
jsx(),
AutoImport({
resolvers: [TDesignResolver({
library: 'vue-next',
})],
dts: false
}),
Components({
resolvers: [TDesignResolver({
library: 'vue-next',
resolveIcons: true
})],
dts: false
}),
vueDevTools()
],
css: {
preprocessorOptions: {
scss: {
additionalData: `
$namespace:${NAMESPACE};
@import "@/styles/index.scss";
`
}
}
},
resolve: {
alias: {
'@': '/src'
}
},
server: {
host: true,
port: 7494,
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
const arr = [
'lodash-es',
'tdesign-icons-vue-next',
'tdesign-vue-next',
['@vueuse/core', 'vueuse'],
'pinyin-pro',
]
for (const item of arr) {
if (typeof item === 'string') {
if (id.includes(item)) return item
}
if (Array.isArray(item)) {
const [key, val] = item
if (id.includes(key)) return val
}
}
if (id.includes('node_modules')) return 'vendor'
}
}
},
chunkSizeWarningLimit: 2048
}
})
function createIndexHtml(): Plugin {
return {
name: 'create-index-html',
config() {
const temp = readFileSync(join(__dirname, 'index.temp.html'), 'utf-8')
writeFileSync(join(__dirname, 'index.html'), temp.replace('SCRIPT_SRC', `./src/main.${importmapMark}.ts`))
}
}
}
function initDataFiles(): Plugin {
return {
name: 'init-data-files',
config() {
// bookmarks-data.json
if (!existsSync(join(__dirname, 'bookmarks-data.json'))) {
writeFileSync(join(__dirname, 'bookmarks-data.json'), '[]')
}
// user-settings.json
if (!existsSync(join(__dirname, 'user-settings.json'))) {
writeFileSync(join(__dirname, 'user-settings.json'), '{}')
}
// theme-config.json
if (!existsSync(join(__dirname, 'theme-config.json'))) {
writeFileSync(join(__dirname, 'theme-config.json'), '{}')
}
}
}
}