-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
103 lines (94 loc) · 2.71 KB
/
vite.config.js
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
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import legacy from '@vitejs/plugin-legacy'
import vue3 from '@vitejs/plugin-vue'
import istanbul from 'vite-plugin-istanbul'
import path from 'path'
import { commonProxy } from './config/proxy-config'
function resolve (dir) {
return path.join(__dirname, dir)
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
process.env = { ...process.env, ...env }
const isNoMock = process.env.NODE_ENV === 'development' && process.env.MOCK_ENV === 'false'
const prod = process.env.NODE_ENV === 'production'
return {
plugins: [
vue3(),
legacy({
targets: ['chrome 39'],
}),
istanbul()
],
resolve: {
alias: [
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url))
},
{
find: '@api-mock',
replacement: isNoMock || prod ? resolve('src/empty') : resolve('src/api-mock')
},
{
find: /~(.+)/,
replacement: fileURLToPath(new URL('./node_modules/$1', import.meta.url))
}
]
},
server: {
host: 'localhost',
port: 8080,
disableHostCheck: true,
proxy: isNoMock ? commonProxy : null
},
build: {
assetsDir: 'static',
sourcemap: true,
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name].[hash].js',
entryFileNames: 'static/[name].[hash].js',
assetFileNames: ({ name }) => {
if (/\.(gif|jpe?g|png|svg)$/.test(name ?? '')) {
return 'static/img/[name].[hash][extname]'
}
if (/\.css$/.test(name ?? '')) {
return 'static/[name].[hash][extname]'
}
if (/\.(ttf|woff2)$/.test(name ?? '')) {
return 'static/fonts/[name]-[hash][extname]'
}
// default value
// ref: https://rollupjs.org/guide/en/#outputassetfilenames
return 'static/[name].[hash][extname]'
}
}
}
},
test: {
globals: true,
environment: 'jsdom',
clearMocks: true,
include: ['tests/specs/**'],
coverage: {
all: true,
enabled: true,
provider: 'istanbul',
reporter: ['lcov', 'text', 'json'],
reportsDirectory: "./tests/coverage",
include: [
// List of files included from coverage
'src/App.vue',
'src/api/**/*.js',
'src/stores/*.js',
'src/utils/**/*.js',
'src/components/**',
'src/pages/**',
]
}
}
}
})