-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
39 lines (35 loc) · 1.06 KB
/
vite.config.js
File metadata and controls
39 lines (35 loc) · 1.06 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { buildTokens } from "./style-dictionary-builder.js";
const tryBuildTokens = async () => {
try {
await buildTokens();
} catch (error) {
console.error(`Token build error: ${error.message}`);
}
};
const tokenWatcherPlugin = () => ({
name: "token-watcher",
async configureServer(server) {
await tryBuildTokens();
server.watcher.add("tokens/**/*.json");
server.watcher.on("change", async (filePath) => {
const isTokenFile =
filePath.includes("tokens/") && filePath.endsWith(".json");
if (!isTokenFile) return;
await tryBuildTokens();
});
},
});
// https://vitejs.dev/config/
export default defineConfig(({ command }) => ({
plugins: [react(), tokenWatcherPlugin()],
// Only use the base path for production builds (when deploying to GitHub Pages)
base: command === 'build' ? "/sd-example-react/" : "/",
resolve: {
alias: {
"@tokens": path.resolve(__dirname, "./src/.cache/tokens"),
},
},
}));