forked from ZenUml/core
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (87 loc) · 2.68 KB
/
Copy pathvite.config.ts
File metadata and controls
92 lines (87 loc) · 2.68 KB
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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { execSync } from "child_process";
import { readFileSync } from "fs";
import svgr from "vite-plugin-svgr";
const gitHash = process.env.DOCKER
? ""
: execSync("git rev-parse --short HEAD").toString().trim();
const gitBranch = process.env.DOCKER
? ""
: execSync("git branch --show-current").toString().trim();
const packageJson = JSON.parse(
readFileSync(resolve(__dirname, "package.json"), "utf-8"),
);
// e2e fixtures and playground/test-compression.html are served via the Vite dev server
// (Playwright launches `bun run dev` — see playwright.config.ts), so they
// don't need to be part of the production site build. Set INCLUDE_E2E_HTML=1
// to bundle them into a built site (rare; only needed if hosting the
// fixtures statically instead of running them via dev server).
function getE2eHtmlFiles() {
const e2eFolder = resolve(__dirname, "e2e");
const strings = execSync(`find ${e2eFolder} -name '*.html'`)
.toString()
.split("\n");
// remove empty string
strings.pop();
return strings;
}
const includeE2eHtml = process.env.INCLUDE_E2E_HTML === "1";
const e2eHtmlFiles = includeE2eHtml ? getE2eHtmlFiles() : [];
const optionalDevHtml = includeE2eHtml
? ["playground/test-compression.html"]
: [];
export default defineConfig(({ mode }) => ({
base: mode === "gh-pages" ? "/zenuml-core/" : "/",
build: {
target: "esnext",
rollupOptions: {
input: [
"index.html",
"embed.html",
"renderer.html",
...optionalDevHtml,
...e2eHtmlFiles,
],
},
},
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
},
server: {
allowedHosts: ["mmd-zenuml-core-app.zenuml.com"],
},
plugins: [svgr(), react()],
define: {
"process.env.NODE_ENV": JSON.stringify(mode),
"process.env.VITE_BUILD_TIME": JSON.stringify(new Date().toISOString()),
"process.env.VITE_VERSION": JSON.stringify(packageJson.version),
"import.meta.env.VITE_APP_GIT_HASH": JSON.stringify(gitHash),
"import.meta.env.VITE_APP_GIT_BRANCH": JSON.stringify(gitBranch),
},
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
},
},
},
test: {
// used by vitest: https://vitest.dev/guide/#configuring-vitest
// need this to run vitest in webstorm ide. vitest has better integration than bun
environment: "jsdom",
reportOnFailure: true,
globals: true,
coverage: {
provider: "v8", // or 'v8'
},
setupFiles: resolve(__dirname, "test/setup.ts"),
exclude: [
"node_modules/**",
"tests/**", // Exclude Playwright tests
],
},
}));