-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
162 lines (159 loc) · 4.73 KB
/
Copy pathvite.config.ts
File metadata and controls
162 lines (159 loc) · 4.73 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { defineConfig, PluginOption } from 'vite'
import { fileURLToPath, URL } from 'url'
import react from '@vitejs/plugin-react-swc'
import mdx from '@mdx-js/rollup'
import remarkFrontmatter from 'remark-frontmatter'
import remarkGfm from 'remark-gfm'
import remarkDirective from 'remark-directive'
import rehypeHighlight from 'rehype-highlight'
import legacy from '@vitejs/plugin-legacy'
import viteCompression from 'vite-plugin-compression'
import { VitePWA } from 'vite-plugin-pwa'
import docsWatcherPlugin from './freeWind/src/vite'
import remarkAdmonition from './freeWind/src/vite/remark-admonition'
import rehypeCodeTitle from './freeWind/src/vite/rehype-code-title'
const NODE_ENV = process.env.NODE_ENV === 'development'
const isSsrBuild = process.argv.includes('--ssr')
const outDir = isSsrBuild ? './dist-server' : './dist'
// https://vite.dev/config/
export default defineConfig({
plugins: [
// 文档监听插件 - 开发模式监听变化,生产模式构建前生成
docsWatcherPlugin(),
// MDX 支持 - 必须放在 react 插件之前
{
enforce: 'pre',
...mdx({
remarkPlugins: [
remarkFrontmatter,
remarkGfm,
remarkDirective,
remarkAdmonition
],
rehypePlugins: [rehypeHighlight, rehypeCodeTitle],
providerImportSource: '@mdx-js/react'
})
} as PluginOption,
// React SWC 编译
react(),
// 兼容旧版或内置浏览器
legacy({
targets: ['defaults', 'iOS >= 12', 'Android >= 7'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime']
}),
// 压缩静态资源。若部署环境已做 gzip/br,请临时注释二者排查重复压缩导致的解析异常
viteCompression({ algorithm: 'gzip', ext: '.gz' }),
viteCompression({ algorithm: 'brotliCompress', ext: '.br' }),
// 注册 PWA
VitePWA({
injectRegister: false,
registerType: 'prompt',
outDir: outDir,
includeAssets: ['icon.ico', 'pwa-192x192.png', 'pwa-512x512.png'],
manifest: {
name: 'ALemonX',
short_name: 'ALemonX',
description: '创建项目、运行命令、管理进程和 Agent 任务',
theme_color: '#0f172a',
background_color: '#f8fafc',
display: 'standalone',
lang: 'zh-CN',
start_url: '/',
icons: [
{
src: '/pwa-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: '/pwa-512x512.png',
sizes: '512x512',
type: 'image/png'
},
{
src: '/maskable-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable'
}
]
},
workbox: {
cleanupOutdatedCaches: true,
clientsClaim: true,
skipWaiting: false
},
devOptions: {
enabled: true
}
})
],
resolve: {
alias: [
{
find: '@free-wind/core',
replacement: fileURLToPath(
new URL('./freeWind/src/index.ts', import.meta.url)
)
},
{
find: '@free-wind/config',
replacement: fileURLToPath(
new URL('./freeWind.config.ts', import.meta.url)
)
},
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url))
}
],
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.md', '.mdx']
},
esbuild: {
drop: NODE_ENV ? [] : ['console', 'debugger']
},
build: {
sourcemap: NODE_ENV, // 仅开发环境生成 sourcemap
cssCodeSplit: true, // 开启 CSS 代码分割
emptyOutDir: true, // 自动清理 dist
commonjsOptions: {
transformMixedEsModules: true
},
minify: 'terser',
terserOptions: {
compress: NODE_ENV
? {}
: {
drop_console: true,
drop_debugger: true
}
},
rollupOptions: {
output: {
dir: outDir,
entryFileNames: isSsrBuild ? '[name].js' : 'js/[name]-[hash].js',
chunkFileNames: 'js/[name]-[hash].js',
assetFileNames: ({ name }) => {
// 自动根据文件类型分类存放
const ext = name?.split('.').pop()
if (ext) return `assets/${ext}/[name]-[hash][extname]`
return 'assets/[name]-[hash][extname]'
},
manualChunks: isSsrBuild
? undefined
: {
'react-vendor': [
'react',
'react-dom',
'react-router-dom',
'react-router',
'react-redux',
'redux',
'@reduxjs/toolkit'
],
'utils-vendor': ['axios', 'dayjs', 'classnames']
}
}
}
}
})