Files
bonaminandClaude Opus 5.5 14d592d963 feat(terminal): older TVs get a legacy build with a compatibility layer; modern output unchanged
- @vitejs/plugin-legacy: browsers without import.meta.resolve (older than Chrome 105 /
  Firefox 106 / Safari 16.4) load a second copy built for Chrome 79 / Firefox 78 / Safari 13
  with polyfills. The modern targets and the stylesheet stay on Vite's own defaults, so modern
  chunks are byte-identical to before (only plugin-legacy's 230-byte guard in the entry).
- terminal/src/compat.js (legacy copy only): swaps in <name>.compat.css (lightningcss for the
  older targets), sets container-size variables for signage slides, emulates flex gap.
- @xenia/signage cq()/CQ_BOX: container units as before where supported, calc(var()) fallback
  otherwise; EmbeddedSlide no longer uses inline `inset`.
- Shared Notice (@xenia/ui); "Devices that work" in Pair a device and Signage -> Screens (EN/EL).
- tests/e2e/compat.mjs: modern browser loads nothing extra; a simulated older TV runs the legacy
  copy and the layer, pairs, and plays a slide at the same sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 17:26:16 +02:00

56 lines
2.5 KiB
JavaScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import legacy from '@vitejs/plugin-legacy'
import { transform } from 'lightningcss'
const BACKEND = process.env.XENIA_BACKEND || 'http://localhost:8000'
// Older TVs (2026-11-21). Modern browsers get exactly the build they always had: Vite's own targets
// (Baseline widely available) for the code and the stylesheet. A browser that can't run it (the
// check is plugin-legacy's: import.meta.resolve, Chrome 105 / Firefox 106 / Safari 16.4) gets a second
// copy of the code, made for LEGACY_TARGETS with the missing pieces added. That copy also loads
// src/compat.js. Modern browsers never download any of it.
const MODERN = ['chrome111', 'edge111', 'firefox114', 'safari16.4', 'ios16.4']
const LEGACY_TARGETS = ['chrome >= 79', 'firefox >= 78', 'safari >= 13']
const COMPAT_CSS = { chrome: 79 << 16, firefox: 78 << 16, safari: 13 << 16 }
/** Each stylesheet again as <name>.compat.css, rewritten for the older browsers (compat.js swaps it in). */
function compatCss() {
return {
name: 'xenia:compat-css',
apply: 'build',
generateBundle(_opts, bundle) {
for (const [name, file] of Object.entries(bundle)) {
if (file.type !== 'asset' || !name.endsWith('.css') || name.endsWith('.compat.css') || name.includes('-legacy')) continue
const { code } = transform({ filename: name, code: Buffer.from(String(file.source)), minify: true, targets: COMPAT_CSS })
this.emitFile({ type: 'asset', fileName: name.replace(/\.css$/, '.compat.css'), source: code })
}
},
}
}
export default defineConfig({
plugins: [
react(),
legacy({ targets: LEGACY_TARGETS, modernTargets: MODERN.map(t => t.replace(/(\D)(\d)/, '$1>=$2')).join(', ') }),
compatCss(),
],
// plugin-legacy would lower the shared stylesheet for everyone; it keeps Vite's own target instead
build: { cssTarget: MODERN },
// npm workspace (D-15): shared packages are imported from source; one React for all.
resolve: {
dedupe: ['react', 'react-dom'],
},
server: {
host: '0.0.0.0',
port: 5175,
// Same origin in production (the image's nginx forwards /api); in dev Vite does it.
// XENIA_BACKEND picks another backend (the e2e suites run their own).
proxy: {
'/api/ws': { target: BACKEND.replace(/^http/, 'ws'), ws: true, changeOrigin: true },
'/api': { target: BACKEND, changeOrigin: true },
'/static': { target: BACKEND, changeOrigin: true },
},
},
})