-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathvite.config.ts
92 lines (87 loc) · 2.04 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
/// <reference types="vitest" />
import { resolve } from 'node:path'
import url from 'url'
import { defineConfig } from 'vite'
import svgr from 'vite-plugin-svgr'
import { checker } from 'vite-plugin-checker'
import react from '@vitejs/plugin-react'
import preserveDirectives from 'rollup-preserve-directives'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const uswdsIncludePaths = [
'node_modules/@uswds',
'node_modules/@uswds/uswds/packages',
]
const VITE_MODE = {
dev: 'dev',
preview: 'preview',
build: 'build',
test: 'test',
benchmark: 'benchmark',
}
export default defineConfig(({ mode }) => {
const isTest = [VITE_MODE.test, VITE_MODE.benchmark].includes(mode)
return {
// ignore some plugins if running tests
plugins: [
react(),
!isTest &&
checker({
typescript: true,
}),
// default svg url pattern is `*.svg?react`, updated to `*.svg?svgr`
svgr({
svgrOptions: { icon: true, memo: true },
include: '**/*.svg?svgr',
}),
preserveDirectives(),
],
build: {
outDir: 'lib',
rollupOptions: {
external: [
'react',
'react-dom',
'react/jsx-runtime',
'focus-trap-react',
'@uswds/uswds',
],
},
sourcemap: true,
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
includePaths: uswdsIncludePaths,
},
},
},
resolve: {
alias: [
{
find: 'uswds',
replacement: resolve(__dirname, './node_modules/@uswds/uswds'),
},
],
},
test: {
globals: true,
setupFiles: ['src/setupTests.ts'],
environment: 'jsdom',
coverage: {
all: false,
// same as jest default (labeled babel)
provider: 'istanbul',
thresholds: {
global: {
statements: 96,
branches: 87,
functions: 94,
lines: 96,
},
},
},
css: false,
},
}
})