generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
95 lines (90 loc) · 2.84 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
/* eslint-disable unicorn/no-abusive-eslint-disable */
/* eslint-disable */
/// <reference types="vitest" />
import importMetaEnv from '@import-meta-env/unplugin';
import eslintPlugin from '@nabla/vite-plugin-eslint';
import react from '@vitejs/plugin-react';
import { defineConfig, loadEnv } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import tsconfigPaths from 'vite-tsconfig-paths';
import svgr from 'vite-plugin-svgr';
// @ts-expect-error Part of code cleanup for post-mvp see: https://github.com/cfpb/sbl-frontend/issues/717
export default async ({ mode }) => {
// NOTE: This is used to load environment variables from ".env" into "process.env" to be used in "vite.config.ts"
// process.env = {...process.env, ...loadEnv(mode, process.cwd())};
// import.meta.env.VITE_NAME available here with: process.env.VITE_NAME
// import.meta.env.VITE_PORT available here with: process.env.VITE_PORT
/* Includes both process.env and .env variables */
const environment = loadEnv(mode, process.cwd(), '');
return defineConfig({
optimizeDeps: {
exclude: [],
},
resolve: {
dedupe: ['react-router-dom'],
},
// @ts-expect-error Part of code cleanup for post-mvp see: https://github.com/cfpb/sbl-frontend/issues/717
test: {
css: false,
include: ['src/**/__tests__/*'],
globals: true,
environment: 'jsdom',
setupFiles: 'src/setupTests.ts',
clearMocks: true,
coverage: {
provider: 'istanbul',
enabled: true,
'100': true,
reporter: ['text', 'lcov'],
reportsDirectory: 'coverage',
},
},
server: {
watch: {
usePolling: true,
},
host: true,
strictPort: true,
port: Boolean(Number(environment.SBL_DEV_PORT))
? Number(environment.SBL_DEV_PORT)
: 8899,
},
plugins: [
svgr(),
tsconfigPaths(),
react(),
importMetaEnv.vite({ example: '.env.example.public' }),
...(mode === 'test'
? []
: [
eslintPlugin(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: [
'icons8-usa-96',
'favicon.png',
'robots.txt',
'apple-touch-icon.png',
'icons/*.svg',
],
manifest: {
theme_color: '#BD34FE',
icons: [
{
src: '/android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any maskable',
},
{
src: '/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
},
}),
]),
],
});
};