-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
vite.config.ts
138 lines (134 loc) · 4.25 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
131
132
133
134
135
136
137
138
/**
* @file vite config
* @module vite.config
* @author Surmon <https://github.com/surmon-china>
* @reference https://vitejs.dev/config/#conditional-config
*/
import path from 'path'
import * as sass from 'sass'
import { loadEnv, defineConfig } from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import UnHeadVite from '@unhead/addons/vite'
import packageJSON from './package.json'
const CWD = process.cwd()
const BASE_ENV_CONFIG = loadEnv('', CWD)
export default defineConfig(({ mode }) => {
const TARGET_ENV_CONFIG = loadEnv(mode, CWD)
// console.info('vite config', { command, mode, TARGET_ENV_CONFIG })
return {
plugins: [vuePlugin(), UnHeadVite()],
root: path.resolve(__dirname),
publicDir: 'public',
resolve: {
alias: {
'/@': path.resolve(__dirname, 'src')
}
},
define: {
__APP_VERSION__: JSON.stringify(packageJSON.version)
},
server: {
open: true,
port: 3000,
proxy: {
[BASE_ENV_CONFIG.VITE_API_PROXY_URL]: {
target: BASE_ENV_CONFIG.VITE_API_ONLINE_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
css: {
preprocessorOptions: {
scss: {
// https://github.com/vitejs/vite/blob/main/docs/config/shared-options.md#csspreprocessoroptions
// https://github.com/vitejs/vite/blob/main/docs/config/shared-options.md#csspreprocessoroptionsextensionadditionaldata
additionalData: `$source-url: '${TARGET_ENV_CONFIG.VITE_FE_URL}';`,
// https://github.com/vitejs/vite/pull/17728#issuecomment-2247114522
api: 'modern',
// https://sass-lang.com/documentation/js-api/interfaces/stringoptions/
charset: false,
importers: [new sass.NodePackageImporter()],
// https://sass-lang.com/documentation/breaking-changes/color-functions/
// https://sass-lang.com/documentation/breaking-changes/import/
silenceDeprecations: ['mixed-decls', 'color-functions']
}
}
},
optimizeDeps: {
include: [
'highlight.js/lib/core',
'highlight.js/lib/languages/go',
'highlight.js/lib/languages/css',
'highlight.js/lib/languages/sql',
'highlight.js/lib/languages/php',
'highlight.js/lib/languages/xml',
'highlight.js/lib/languages/json',
'highlight.js/lib/languages/bash',
'highlight.js/lib/languages/less',
'highlight.js/lib/languages/scss',
'highlight.js/lib/languages/yaml',
'highlight.js/lib/languages/rust',
'highlight.js/lib/languages/shell',
'highlight.js/lib/languages/nginx',
'highlight.js/lib/languages/stylus',
'highlight.js/lib/languages/python',
'highlight.js/lib/languages/javascript',
'highlight.js/lib/languages/typescript'
],
exclude: [
// browser
'intersection-observer',
// server
'express',
'lru-cache',
'cookie-parser',
'serialize-javascript',
'wonderful-bing-wallpaper'
]
},
build: {
sourcemap: true,
manifest: true,
rollupOptions: {
// disable vite warning
// https://github.com/vitejs/vite/pull/10331
// https://github.com/vitejs/vite/issues/10766
external: [/^\/images\/(?:[^/]+\/)*[^/]+$/],
output: {
entryFileNames: '[name]-[hash].js',
chunkFileNames: '[name]-[hash].js',
assetFileNames: '[name]-[hash].[ext]',
manualChunks: {
sentry: ['@sentry/vue'],
vendor: [
'vue',
'vue-router',
'pinia',
'@unhead/vue',
'@unhead/schema',
'axios',
'qs',
'swiper',
'lozad',
'qrcode',
'geojson',
'js-cookie',
'lodash-es',
'marked',
'marked-highlight',
'marked-mangle',
'marked-xhtml',
'emoji-233333',
'highlight.js',
'ua-parser-js',
'bezier-easing',
'intersection-observer',
'@braintree/sanitize-url'
]
}
}
}
}
}
})