-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvite.config.ts
116 lines (108 loc) · 3.56 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
/// <reference types="vitest" />
import { sentryVitePlugin } from "@sentry/vite-plugin";
import react from "@vitejs/plugin-react";
import { visualizer } from "rollup-plugin-visualizer";
import { defineConfig, mergeConfig } from "vite";
import { checker } from "vite-plugin-checker";
import envCompatible from "vite-plugin-env-compatible";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig as defineTestConfig } from "vitest/config";
import dns from "dns";
import path from "path";
import injectVariablesInHTML from "./config/injectVariablesInHTML";
// Remove when https://github.com/cypress-io/cypress/issues/25397 is resolved.
dns.setDefaultResultOrder("ipv4first");
// https://vitejs.dev/config/
const viteConfig = defineConfig({
build: {
rollupOptions: {
plugins: [],
},
sourcemap: true,
},
plugins: [
tsconfigPaths(),
react({
babel: {
// @emotion/babel-plugin injects styled component names (e.g. "StyledSelect") into HTML for dev
// environments only. It can be toggled for production environments by modifying the parameter
// autoLabel. (https://emotion.sh/docs/@emotion/babel-plugin)
plugins: ["@emotion/babel-plugin", "import-graphql"],
},
// Exclude storybook stories from fast refresh.
exclude: /\.stories\.tsx?$/,
// Only Typescript files should use fast refresh.
include: ["**/*.tsx", "**/*.ts"],
// Enables use of css prop on JSX.
jsxImportSource: "@emotion/react",
}),
envCompatible({
prefix: "REACT_APP_",
}),
injectVariablesInHTML({
files: "dist/index.html",
variables: [
"%REACT_APP_VERSION%",
"%GIT_SHA%",
"%REACT_APP_RELEASE_STAGE%",
"%NODE_ENV%",
"%PROFILE_HEAD%",
],
}),
// Typescript checking
checker({ typescript: true }),
// Bundle analyzer
visualizer({
filename: "dist/source_map.html",
template: "treemap",
}),
sentryVitePlugin({
authToken: process.env.PARSLEY_SENTRY_AUTH_TOKEN,
disable: process.env.NODE_ENV === "development",
org: "mongodb-org",
project: "parsley",
release: {
name: process.env.npm_package_version,
},
sourcemaps: {
assets: "dist/assets/*",
},
}),
],
// Setting jsxImportSource to @emotion/react raises a warning in the console. This line silences
// the warning. (https://github.com/vitejs/vite/issues/8644)
esbuild: {
logOverride: { "this-is-undefined-in-esm": "silent" },
},
// The resolve field for @leafygreen-ui/emotion is to prevent LG from pulling in SSR dependencies.
// It can be potentially removed upon the completion of https://jira.mongodb.org/browse/PD-1543.
resolve: {
alias: {
"@leafygreen-ui/emotion": path.resolve(
__dirname,
"./config/leafygreen-ui/emotion.ts",
),
...(process.env.PROFILER === "true" && {
"react-dom/client": path.resolve(
__dirname,
"../../node_modules/react-dom/profiling",
),
"scheduler/tracing": path.resolve(
__dirname,
"../../node_modules/scheduler/tracing-profiling",
),
}),
},
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
},
});
const vitestConfig = defineTestConfig({
test: {
environment: "jsdom",
globals: true,
outputFile: { junit: "./bin/vitest/junit.xml" },
reporters: ["default", ...(process.env.CI === "true" ? ["junit"] : [])],
setupFiles: "./config/vitest/setupTests.ts",
},
});
export default mergeConfig(viteConfig, vitestConfig);