forked from AnsGoo/openDataV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
96 lines (92 loc) · 2.48 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
import type { UserConfigExport, ConfigEnv, ProxyOptions } from 'vite'
import { loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import MarkDownPlugin from 'vite-plugin-vue-markdown'
import { viteMockServe } from 'vite-plugin-mock'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default ({ mode, command }: ConfigEnv): UserConfigExport => {
const { VITE_APP_PORT, VITE_APP_PROXY, VITE_MOCK } = loadEnv(mode, process.cwd())
const createProxy = (propxyList) => {
const ret = {} as Record<string, ProxyOptions>
for (const [prefix, target] of propxyList) {
ret[prefix] = {
target: target,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), '')
}
}
return ret
}
return {
plugins: [
vue({
include: [/\.vue$/, /\.md$/] // <--
}),
vueJsx(),
viteMockServe({
mockPath: 'mock',
supportTs: true, //如果使用 js发开,则需要配置 supportTs 为 false
logger: true,
localEnabled: command === 'serve',
prodEnabled: VITE_MOCK === 'true',
injectCode: `
import { setupProdMockServer } from '../mock/mockProdServer';
setupProdMockServer();
`
}),
MarkDownPlugin({
markdownItSetup(md) {
md.use(require('./build/toc.js'))
}
})
],
base: './',
resolve: {
alias: {
// 路径别名
'@': resolve(__dirname, 'src')
},
// 使用路径别名时想要省略的后缀名,官方不建议将.vue文件省略后缀
extensions: ['.js', '.ts']
},
server: {
// 是否开启 https
https: false,
port: Number(VITE_APP_PORT),
host: '0.0.0.0',
open: false,
proxy: createProxy(JSON.parse(VITE_APP_PROXY)),
fs: {
allow: ['..'],
strict: false
},
cors: true
},
build: {
target: 'es2015',
chunkSizeWarningLimit: 1500,
terserOptions: {
compress: {
keep_infinity: true,
// Used to delete console in production environment
drop_console: true
}
}
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
hack: `true; @import (reference) "${resolve('src/css/index.less')}";`
},
javascriptEnabled: true
}
},
modules: {
localsConvention: 'camelCase'
}
}
}
}