-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvite.config.ts
130 lines (127 loc) · 3.36 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
128
129
130
import { defineConfig, Plugin, PluginOption } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import DocServer from './src/plugins/DocServer'
import DocBuildMove from './src/plugins/DocBuildMove'
import StatisticInfoGenerator from './src/plugins/StatisticInfoGenerator'
import CommitTotalTrendGenerator from './src/plugins/CommitTotalTrendGenerator'
import BuildTimeGenerator from './src/plugins/BuildTimeGenerator'
import VitePluginPrismjs from 'vite-plugin-prismjs'
import DataGenrator from './src/plugins/DataGenerator'
import {visualizer} from "rollup-plugin-visualizer"
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { VitePWA } from 'vite-plugin-pwa'
const plugins: Plugin[] = [];
// 打包生产环境才引入的插件
if (process.env.NODE_ENV === "production") {
// 打包依赖展示
plugins.push(
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
filename: "dist/stats.html"
}) as Plugin
);
}
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "src")
},
},
server: {
fs: {
strict: false
},
host: '0.0.0.0',
hmr: { clientPort: process.env.CODESPACES ? 443 : undefined }
},
plugins: [
...plugins,
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico'],
workbox: {
globPatterns: ['**/index.html', '**/*.{js,css,json}'],
},
manifest: {
name: '知识体系',
short_name: 'PKS',
description: '知识体系',
theme_color: '#ffffff',
icons: [
{
src: 'logo-192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: 'logo-512.png',
sizes: '512x512',
type: 'image/png'
}
]
}
}),
vue(),
DocServer(),
BuildTimeGenerator(),
{
...DocBuildMove(),
enforce: 'post',
apply: 'build'
},
{
...StatisticInfoGenerator(),
apply: 'build'
},
{
...CommitTotalTrendGenerator(),
apply: 'build'
},
{
...DataGenrator(),
apply: 'build'
},
{
...VitePluginPrismjs({
"languages": ["javascript", "css", "markup", "java", "sql",
'c', 'go', 'python', 'ts', 'ruby', 'io', 'scala', 'groovy',
'kotlin', 'ini', 'json', 'graphql', 'haskell', 'clojure', 'rust'],
"plugins": ["line-numbers"]
}),
},
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
build: {
assetsDir: "resource",
emptyOutDir: false,
rollupOptions: {
output: {
manualChunks(id: string): string {
const indepentDependcies = ['element-plus', 'vue', 'jspdf',
'html2canvas', 'echarts', 'zrender', 'marked', 'mermaid',
'katex', 'elkjs', 'cytoscape']
for (let depend of indepentDependcies) {
if (id.includes('node_modules') && id.includes(depend)) {
return depend
}
}
if (id.includes('node_modules')) {
return 'vendor'
}
return ''
}
}
}
},
})