forked from microbit-foundation/python-editor-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
66 lines (63 loc) · 1.66 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
import { configDefaults, defineConfig, UserConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import {
IndexHtmlTransformContext,
IndexHtmlTransformResult,
loadEnv,
Plugin,
} from "vite";
import fs from "node:fs";
import path from "node:path";
import ejs from "ejs";
// Support optionally pulling in external branding if the module is installed.
const theme = "@microbit-foundation/python-editor-v3-microbit";
const external = `node_modules/${theme}`;
const internal = "src/deployment/default";
// There are third-party options but seems better to just depend on ejs.
const viteEjsPlugin = ({ data }: { data: ejs.Data }): Plugin => ({
name: "ejs",
transformIndexHtml: {
order: "pre",
handler: (
html: string,
_ctx: IndexHtmlTransformContext
): IndexHtmlTransformResult => ejs.render(html, data),
},
});
export default defineConfig(({ mode }) => {
const unitTest: UserConfig["test"] = {
globals: true,
exclude: [...configDefaults.exclude, "**/e2e/**"],
environment: "jsdom",
setupFiles: "./src/setupTests.ts",
mockReset: true,
};
const config: UserConfig = {
base: process.env.BASE_URL ?? "/",
build: {
outDir: "build",
sourcemap: true,
},
server: {
port: 3000,
},
assetsInclude: ["**/*.hex"],
plugins: [
viteEjsPlugin({
data: loadEnv(mode, process.cwd(), "VITE_"),
}),
react(),
svgr(),
],
test: unitTest,
resolve: {
alias: {
"theme-package": fs.existsSync(external)
? theme
: path.resolve(__dirname, internal),
},
},
};
return config;
});