-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
75 lines (70 loc) · 1.9 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
67
68
69
70
71
72
73
74
75
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite';
import { VitePWA } from 'vite-plugin-pwa'
import { resolve } from 'node:path';
import { execSync } from "child_process";
import { readFileSync, writeFileSync } from "fs";
const commitHash = execSync("git rev-parse --short HEAD").toString().trim();
const packageJson = JSON.parse(
readFileSync("./package.json").toString("utf-8"),
);
process.env.VITE_GIT_COMMIT = commitHash;
process.env.VITE_APP_VERSION = packageJson.version;
// https://vite.dev/config/
export default defineConfig({
plugins: [
preact(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'mask-icon.svg'],
manifest: {
name: 'Kalkki',
short_name: 'Kalkki',
description: 'Selainpohjainen tieteislaskin',
theme_color: '#1D2D35',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png'
}
],
lang: 'fi',
}
}),
{
name: 'generate-manifest',
apply: 'build',
closeBundle() {
// Manifest data
const manifest = {
version: packageJson.version,
gitHash: commitHash,
buildDate: new Date().toISOString(),
};
// Write manifest.json to the dist directory
const distPath = resolve('dist', 'manifest.json');
writeFileSync(distPath, JSON.stringify(manifest, null, 2));
console.log('✅ Manifest generated:', distPath);
},
},
],
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
app: resolve(__dirname, 'app.html')
}
}
},
resolve: {
alias: {
'@': resolve(__dirname, "./src"),
},
},
})