forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
41 lines (36 loc) · 1.12 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
import { definePlaygroundViteConfig } from "@typespec/playground/vite";
import { execSync } from "child_process";
import { visualizer } from "rollup-plugin-visualizer";
import { defineConfig, loadEnv } from "vite";
import { TypeSpecPlaygroundConfig } from "./src/index.js";
function getCommit() {
return execSync("git rev-parse HEAD").toString().trim();
}
function getPrNumber() {
// Set by Azure DevOps.
return process.env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"];
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const useLocalLibraries = env["VITE_USE_LOCAL_LIBRARIES"] === "true";
const config = definePlaygroundViteConfig({
...TypeSpecPlaygroundConfig,
links: {
documentationUrl: "https://microsoft.github.io/typespec",
},
skipBundleLibraries: !useLocalLibraries,
});
config.plugins!.push(
visualizer({
filename: "temp/stats.html",
}) as any
);
const prNumber = getPrNumber();
if (prNumber) {
config.define = {
__PR__: JSON.stringify(prNumber),
__COMMIT_HASH__: JSON.stringify(getCommit()),
};
}
return config;
});