33 lines
990 B
JavaScript
33 lines
990 B
JavaScript
import fs from 'node:fs';
|
|
import { defineConfig } from 'vite';
|
|
|
|
const VERSION_FILE = new URL('./src/version.json', import.meta.url);
|
|
|
|
// src/version.json is imported by the app (baked into the bundle) and also
|
|
// published as /version.json, which running clients poll to detect new deploys.
|
|
function versionFilePlugin() {
|
|
return {
|
|
name: 'quartiles-version-file',
|
|
// Dev: always serve the current file contents, uncached
|
|
configureServer(server) {
|
|
server.middlewares.use('/version.json', (req, res) => {
|
|
res.setHeader('Content-Type', 'application/json');
|
|
res.setHeader('Cache-Control', 'no-store');
|
|
res.end(fs.readFileSync(VERSION_FILE, 'utf8'));
|
|
});
|
|
},
|
|
// Build: emit dist/version.json
|
|
generateBundle() {
|
|
this.emitFile({
|
|
type: 'asset',
|
|
fileName: 'version.json',
|
|
source: fs.readFileSync(VERSION_FILE, 'utf8')
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [versionFilePlugin()]
|
|
});
|