This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvite.config.ts
108 lines (103 loc) · 2.83 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
/// <reference types="vitest" />
/// <reference types="vite/client" />
/* Copyright (c) 2021-2023 Nordcloud Oy or its affiliates. All Rights Reserved. */
import path from "path";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import envCompatible from "vite-plugin-env-compatible";
import svgrPlugin from "vite-plugin-svgr";
import { createHtmlPlugin } from "vite-plugin-html";
import checker from "vite-plugin-checker";
import { configDefaults } from "vitest/config";
import { codeVersion } from "./scripts/code-version";
const ENV_PREFIX = "REACT_APP_";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, "env", [ENV_PREFIX, "SERVER"]);
const isProd = env.REACT_APP_ENV === "production";
return {
plugins: [
envCompatible({ prefix: ENV_PREFIX }),
checker({
overlay: false,
typescript: true,
}),
createHtmlPlugin({
inject: {
data: {
env: {
NODE_ENV: process.env.NODE_ENV,
REACT_APP_CLIENT_TOKEN: env.REACT_APP_CLIENT_TOKEN,
REACT_APP_ENV: env.REACT_APP_ENV,
},
},
},
minify: true,
}),
svgrPlugin({
svgrOptions: {
icon: true,
// ...svgr options (https://react-svgr.com/docs/options/)
},
}),
react({
babel: {
plugins: [
[
"babel-plugin-styled-components",
{
displayName: true,
fileName: false,
},
],
],
},
}),
],
resolve: {
alias: {
"~": path.resolve(__dirname, "src"),
},
},
server: {
port: 3000,
open: env.SERVER_OPEN_BROWSER === "true",
},
define: {
"process.env.CODE_VERSION": JSON.stringify(codeVersion()), // Useful for uploading sourcemaps
},
build: {
outDir: "build",
sourcemap: isProd ? "hidden" : true,
},
test: {
globals: true,
environment: "jsdom",
setupFiles: "src/setupTests.ts",
testTimeout: 10000,
teardownTimeout: 180000,
clearMocks: true,
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
coverage: {
src: ["src"],
include: ["src/**/*.{ts,tsx}"],
exclude: [
...(configDefaults.coverage.exclude ?? []),
"src/setupTests.ts",
"src/**/__mockups__/**",
"src/**/__tests__/**",
"src/**/*.spec.ts",
"src/**/*.spec.tsx",
],
reporter: ["text", "lcovonly"],
provider: "v8",
all: true,
lines: 45,
branches: 35,
functions: 35,
statements: 45,
},
reporters: process.env.CI ? ["default"] : ["default", "verbose"],
},
};
});