-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
133 lines (131 loc) · 4.16 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
import { splitVendorChunkPlugin } from 'vite';
import { defineConfig, UserConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import checker from 'vite-plugin-checker';
import wranglerPlugin from './scripts/vite-plugin-wrangler';
import clearVitest from './scripts/vite-plugin-clear-vitest';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import generateTypes, { generateTypesFilePath } from './scripts/vite-plugin-generate-types';
import path from 'node:path';
const TEST = typeof process !== 'undefined' && process.env.NODE_ENV === 'test';
const DEV = !TEST;
const event = process.env.npm_lifecycle_event;
const WATCH_TEST = TEST && event === 'test';
const generateTypesConfig: UserConfig['test'] =
event === 'dev' || event === 'build'
? {
environment: 'node',
globals: true,
include: [generateTypesFilePath],
css: false,
isolate: false,
passWithNoTests: true,
coverage: {
enabled: false,
},
}
: undefined;
// https://vitejs.dev/config/
export default defineConfig(({ command }) => ({
// When generating types, run in node environment
test: generateTypesConfig ?? {
env: {
// "ExperimentalWarning: The Fetch API is an experimental feature."
// Remove when fetch is no longer experimental
NODE_NO_WARNINGS: '1',
},
environment: 'happy-dom',
globals: true,
setupFiles: ['./setup.vitest.ts'],
include: ['src/**/*.test.{ts,tsx}', 'server/**/*.test.{ts,tsx}'],
css: false,
deps: {
fallbackCJS: true,
},
// https://github.com/bcoe/c8#cli-options--configuration
coverage: {
enabled: true,
include: ['src/**/*.{ts,tsx}', 'server/**/*.{ts,tsx}'],
exclude: [
'src/**/*.test.{ts,tsx}',
'server/**/*.test.{ts,tsx}',
'src/**/*.css.ts',
'src/app/utils/constants.ts',
'src/app/utils/test-utils.ts',
'src/app/utils/runtime-error-overlay.ts',
'server/dev-server.tsx',
],
'100': true, // 100% coverage
},
},
plugins: [
react(),
!TEST && generateTypes(command),
process.argv.includes('--server') ? wranglerPlugin() : undefined,
DEV &&
checker({
typescript: true,
eslint: {
lintCommand: 'eslint -c .eslintrc.json --cache --fix --ext ts,tsx src',
dev: {
logLevel: ['error'],
},
},
}),
// Clear terminal plugin for vitest
WATCH_TEST && clearVitest(),
vanillaExtractPlugin({
identifiers: command === 'serve' ? 'debug' : 'short',
}),
command === 'build' ? splitVendorChunkPlugin() : undefined,
],
// TODO
// Submit fix to esbuild for 'linked': https://github.com/evanw/esbuild/blob/master/pkg/api/api_impl.go#L1458
// or change to 'eof', read eof and move to txt and link
esbuild: {
legalComments: 'none',
},
resolve: {
alias: {
img: path.resolve(__dirname, './src/img'),
components: path.resolve(__dirname, './src/app/components'),
elements: path.resolve(__dirname, './src/app/elements'),
containers: path.resolve(__dirname, './src/app/containers'),
groups: path.resolve(__dirname, './src/app/groups'),
routes: path.resolve(__dirname, './src/app/routes'),
sections: path.resolve(__dirname, './src/app/sections'),
store: path.resolve(__dirname, './src/app/store'),
utils: path.resolve(__dirname, './src/app/utils'),
common: path.resolve(__dirname, './src/app/common'),
machines: path.resolve(__dirname, './src/app/machines'),
types: path.resolve(__dirname, './src/app/types'),
server: command === 'serve' ? './server' : path.resolve(__dirname, './server'),
},
},
build: {
rollupOptions: {
external: ['./utils/runtime-error-overlay'],
},
},
server: {
port: 3000,
watch: {
ignored: ['/coverage'],
},
proxy: {
'/server': 'http://localhost:8080/',
'/api': 'http://localhost:8080/',
},
open: true,
},
preview: {
port: 3001,
},
json: {
stringify: true,
},
optimizeDeps: {
// Fix vite being unable to discover zod after updating an npm package
include: ['zod'],
},
}));