-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
56 lines (49 loc) · 1.46 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
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig, type Plugin, type PluginOption } from 'vite';
import { promises as fs, existsSync } from 'fs';
import path from 'path';
import dotenv from 'dotenv';
import prettier from 'prettier';
import { generateFullTheme } from './src/styles/generators';
const makeThemeFile = async () => {
const cssContent = generateFullTheme();
let formattedContent = '';
try {
formattedContent = await prettier.format(cssContent, {
parser: 'css'
});
} catch (e) {
console.error(e);
formattedContent = cssContent;
}
const outputDir = './src/styles'; // Ensure this directory exists or use your path
if (!existsSync(outputDir)) {
await fs.mkdir(outputDir);
}
await fs.writeFile(path.resolve(outputDir, 'palette.css'), formattedContent);
};
const colorGeneratorPlugin = (): Plugin => {
return {
name: 'vite-plugin-color-generator',
buildStart: async () => {
await makeThemeFile();
}
};
};
// Load environment variables from .env files
dotenv.config({ path: '.env' });
dotenv.config({ path: '.env.local' });
export default defineConfig(({ mode }) => {
const plugins: PluginOption[] = [];
// Load development or production .env file based on Vite mode
if (mode === 'development') {
dotenv.config({ path: '.env.development' });
plugins.push(colorGeneratorPlugin());
} else if (mode === 'production') {
dotenv.config({ path: '.env.production' });
}
plugins.push(sveltekit());
return {
plugins
};
});