52 lines
1.7 KiB
JavaScript
52 lines
1.7 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;
|
|
|
|
// Options for date formatting
|
|
const dateTimeFormatOptions = {
|
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
hour12: false // Use 24-hour format
|
|
};
|
|
// Generate build time string using Slovak locale
|
|
const appBuildTime = new Date().toLocaleString('sk-SK', dateTimeFormatOptions);
|
|
|
|
|
|
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') // Assuming sw.js is now in src
|
|
},
|
|
output: {
|
|
entryFileNames: assetInfo => {
|
|
// Output service-worker.js to the root of the dist directory
|
|
if (assetInfo.name === 'sw') {
|
|
return 'service-worker.js'; // Ensure consistent name
|
|
}
|
|
// Default naming for other entry points/chunks
|
|
return 'assets/[name]-[hash].js';
|
|
},
|
|
// For chunks, if any are generated from sw.js (unlikely for simple SW)
|
|
chunkFileNames: 'assets/[name]-[hash].js',
|
|
assetFileNames: 'assets/[name]-[hash].[ext]',
|
|
}
|
|
},
|
|
// Set to false if you don't want to empty the dist dir on each build
|
|
// but usually true is good for clean builds.
|
|
emptyOutDir: true,
|
|
}
|
|
}); |