Files
nexus-timer/vite.config.js
2025-05-09 23:19:39 +02:00

61 lines
1.8 KiB
JavaScript

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import fs from 'fs';
import { resolve } from 'path';
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const appVersion = packageJson.version;
const now = new Date();
const dateTimeFormat = new Intl.DateTimeFormat('sk-SK', {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit',
hour12: false
});
const parts = dateTimeFormat.formatToParts(now);
let day = '', month = '', year = '', hour = '', minute = '', second = '';
parts.forEach(part => {
switch (part.type) {
case 'day': day = part.value; break;
case 'month': month = part.value; break;
case 'year': year = part.value; break;
case 'hour': hour = part.value; break;
case 'minute': minute = part.value; break;
case 'second': second = part.value; break;
}
});
// Assemble the date part without unwanted spaces
const appBuildTime = `${day}.${month}.${year} ${hour}:${minute}:${second}`;
export default defineConfig({
plugins: [vue()],
server: {
port: 8080
},
define: {
'import.meta.env.VITE_APP_BUILD_TIME': JSON.stringify(appBuildTime),
'__APP_CACHE_VERSION__': JSON.stringify(`nexus-timer-cache-v${appVersion}-${Date.now()}`)
},
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
sw: resolve(__dirname, 'src/sw.js')
},
output: {
entryFileNames: assetInfo => {
if (assetInfo.name === 'sw') {
return 'service-worker.js';
}
return 'assets/[name]-[hash].js';
},
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
}
},
emptyOutDir: true,
}
});