47 lines
2.1 KiB
TypeScript
47 lines
2.1 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import { fileURLToPath, URL } from 'node:url';
|
|
import pkg from './package.json';
|
|
|
|
// The build's own name, handed to the bundle as an env var and printed at the
|
|
// foot of the studio's tab rail. The caller names it (`VERSION=$(git rev-parse
|
|
// --short HEAD) docker compose build`, see Dockerfile); left alone, the build
|
|
// stamps the minute it ran, so two builds are never the same name and an
|
|
// operator can tell which image is up.
|
|
const version = `${pkg.version}+${process.env.VERSION || new Date().toISOString().slice(0, 16).replace(/[-:T]/g, '')}`;
|
|
// Vite hands the VITE_ ones to the page, and it reads this very `process.env`
|
|
// when it builds `import.meta.env` — so the name is set here and read there.
|
|
process.env.VITE_VERSION = version;
|
|
|
|
// The app is shared source with the React Native app: `frameUtils.ts` and
|
|
// `skiaImage.ts` import `@shopify/react-native-skia`, and the alias below swaps
|
|
// that for the CanvasKit adapter. Same trick the W0 spike used, now for the app.
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
resolve: {
|
|
// onnxruntime-web ships two flavours of its default entry: one with the
|
|
// runtime's wasm inlined as a build asset, one that fetches it at runtime.
|
|
// This picks the second, so the 28MB binary is served from /wasm/ort/ (see
|
|
// scripts/copy-wasm.mjs) instead of being emitted twice into dist.
|
|
conditions: ['onnxruntime-web-use-extern-wasm'],
|
|
alias: {
|
|
'@shopify/react-native-skia': fileURLToPath(new URL('./src/engine/skiaShim.ts', import.meta.url)),
|
|
},
|
|
},
|
|
build: {
|
|
target: 'es2022',
|
|
// canvaskit-wasm's glue JS is ~2.5MB on its own; the wasm is fetched at
|
|
// runtime from /wasm/, never bundled.
|
|
chunkSizeWarningLimit: 9000,
|
|
},
|
|
optimizeDeps: {
|
|
// libraw-wasm and libheif-js start their own worker/wasm. Pre-bundling moves modules
|
|
// into .vite/deps/, breaking relative WASM layout.
|
|
exclude: ['libraw-wasm', 'libheif-js'],
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
proxy: { '/api': process.env.API_ORIGIN ?? 'http://localhost:3000' },
|
|
},
|
|
});
|