password_manager/vite.config.js
hermes-explorigin aa651568af
Some checks failed
Test, Build & Deploy / test-and-build (push) Failing after 1m15s
Test, Build & Deploy / deploy (push) Has been skipped
Add CI workflow + baked commit hash
- .gitea/workflows/deploy.yml: test+build on every push; auto-deploy
  dist/index.html to /password_manager via WebDAV on push to main (DELETE-
  then-PUT to bypass stale-file cache), verifying deployed bytes match.
- Build injects __VAULT_COMMIT__ (from VITE_COMMIT_HASH=github.sha in CI,
  git HEAD locally) and main.js logs console.info({ commit_hash }) on
  startup so a deploy is verifiable against its source commit.
2026-08-30 19:12:19 +00:00

48 lines
1.3 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: {
__VAULT_COMMIT__: JSON.stringify(getCommitHash()),
},
plugins: [
svelte(),
...(command === 'build'
? [viteSingleFile({
inlineStyles: true,
inlineScripts: true,
removeUnusedCss: true,
removeViteModuleLoader: true,
})]
: []),
],
build: {
target: 'esnext',
minify: false,
},
preview: {
allowedHosts: ["dev.thecookiejar.me"]
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./tests/setup.js'],
include: ['src/**/*.test.js', 'tests/**/*.test.js'],
},
}))