This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
vite.config.ts
154 lines (150 loc) · 4.01 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { defineConfig } from "vite";
import { sentryVitePlugin } from "@sentry/vite-plugin";
import react from "@vitejs/plugin-react";
import * as fs from "fs";
import path from "path";
import vitePluginImp from "vite-plugin-imp";
import { viteCommonjs, esbuildCommonjs } from "@originjs/vite-plugin-commonjs";
import envCompatible from "vite-plugin-env-compatible";
import checker from "vite-plugin-checker";
import { visualizer } from "rollup-plugin-visualizer";
import tsconfigPaths from "vite-tsconfig-paths";
import dns from "dns";
import injectVariablesInHTML from "./config/injectVariablesInHTML";
// Remove when https://github.com/cypress-io/cypress/issues/25397 is resolved.
dns.setDefaultResultOrder("ipv4first");
// Do not apply Antd's global styles
fs.writeFileSync(require.resolve("antd/es/style/core/global.less"), "");
fs.writeFileSync(require.resolve("antd/lib/style/core/global.less"), "");
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 3000,
proxy: {
"/graphql": {
target: "http://localhost:9090/graphql/query",
changeOrigin: true,
},
},
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: "globalThis",
},
// Enable esbuild polyfill plugins
plugins: [esbuildCommonjs(["antd"])],
},
},
build: {
sourcemap: true,
outDir: "build",
rollupOptions: {
output: {
plugins: [
// Replace the variables in our HTML files.
injectVariablesInHTML({
files: "build/index.html",
variables: [
"%APP_VERSION%",
"%GIT_SHA%",
"%REACT_APP_RELEASE_STAGE%",
"%NEW_RELIC_ACCOUNT_ID%",
"%NEW_RELIC_LICENSE_KEY%",
"%NEW_RELIC_TRUST_KEY%",
"%SPRUCE_NEW_RELIC_AGENT_ID%",
"%SPRUCE_NEW_RELIC_APPLICATION_ID%",
],
}),
],
manualChunks: {
vendor: [
"react",
"react-router-dom",
"react-dom",
"react-router",
"lodash",
"date-fns",
"antd",
"date-fns/esm/locale",
],
},
},
},
},
resolve: {
alias: {
"@leafygreen-ui/emotion": path.resolve(
__dirname,
"./config/leafygreen-ui/emotion",
),
},
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
},
plugins: [
tsconfigPaths(),
viteCommonjs(),
// Inject env variables
envCompatible({
prefix: "REACT_APP_",
}),
// Use emotion jsx tag instead of React.JSX
react({
jsxImportSource: "@emotion/react",
babel: {
plugins: ["@emotion/babel-plugin", "import-graphql"],
},
// exclude storybook stories
exclude: [/\.stories\.tsx?$/],
}),
// Dynamic imports of antd styles
vitePluginImp({
optimize: true,
libList: [
{
libName: "antd",
libDirectory: "es",
style: (name) => `antd/es/${name}/style/index.js`,
},
{
libName: "lodash",
libDirectory: "",
camel2DashComponentName: false,
style: (name) => `lodash/${name}`,
},
{
libName: "date-fns",
libDirectory: "esm",
style: (name) => `date-fns/esm/${name}`,
camel2DashComponentName: false,
},
],
}),
// Typescript checking
checker({ typescript: true }),
// Bundle analyzer
visualizer({
filename: "build/source_map.html",
template: "treemap",
}),
sentryVitePlugin({
org: "mongodb-org",
project: "spruce",
authToken: process.env.SPRUCE_SENTRY_AUTH_TOKEN,
release: {
name: process.env.npm_package_version,
},
sourcemaps: {
assets: "./build/assets/*",
},
}),
],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true, // enable LESS {@import ...}
},
},
},
});