weather_app/vite.config.js
hermes-explorigin 38f0c04b3e
Some checks failed
Test, Build & Deploy / test-and-build (push) Successful in 38s
Test, Build & Deploy / deploy (push) Failing after 20s
Bake commit hash into build; log it via console.info on startup
Build injects __WEATHER_COMMIT__ (VITE_COMMIT_HASH from CI's github.sha on
branch builds, git rev-parse HEAD locally) and main.js logs
console.info({ commit_hash }) so a deploy can be verified to match the
commit that produced it.
2026-08-30 19:01:13 +00:00

54 lines
1.4 KiB
JavaScript

import { execSync } from 'node:child_process'
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { viteSingleFile } from 'vite-plugin-singlefile'
// https://vite.dev/config/
// Bake the commit hash into the bundle at build time so a deployed app can
// report exactly which commit produced it (logged via console.info at startup).
// CI sets VITE_COMMIT_HASH=${{ github.sha }}; local builds fall back to git HEAD.
function getCommitHash() {
if (process.env.VITE_COMMIT_HASH) return process.env.VITE_COMMIT_HASH
try {
return execSync('git rev-parse HEAD').toString().trim()
} catch {
return 'unknown'
}
}
export default defineConfig(({ command }) => ({
define: {
__WEATHER_COMMIT__: JSON.stringify(getCommitHash()),
},
plugins: [
svelte(),
...(command === 'build'
? [viteSingleFile({
inlineStyles: true,
inlineScripts: true,
removeUnusedCss: true,
removeViteModuleLoader: true,
})]
: []),
],
build: {
target: 'esnext',
minify: false,
rollupOptions: {
treeshake: {
moduleSideEffects: true,
annotations: false,
},
},
},
preview: {
allowedHosts: ["dev.thecookiejar.me"]
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./tests/setup.js'],
include: ['src/**/*.test.js', 'tests/**/*.test.js'],
},
}))