Skip to content

Commit 546b437

Browse files
kinlaneclaude
andcommitted
Run Locally: strip crossorigin so CSS loads over file://
Vite stamps crossorigin on the injected <link>/<script>. Over file:// a crossorigin stylesheet is a CORS request against a null origin with no CORS headers, so the browser refuses to apply the CSS — the exact "CSS doesn't load when I open the download" symptom. A post-order transformIndexHtml plugin now removes the attribute; harmless no-op on the same-origin live site. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 25f0711 commit 546b437

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

vite.config.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,27 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills';
44
// Static SPA. Use a RELATIVE base ('./') so the built assets resolve no matter
55
// where the app is served from — the custom domain root (validator.apicommons.org)
66
// AND an unzipped "Run Locally" copy served from any folder.
7+
// Strip the `crossorigin` attribute Vite stamps on the injected <link>/<script>
8+
// tags. On the live (same-origin) site it's a harmless no-op, but when the
9+
// unzipped "Run Locally" copy is opened over file://, a crossorigin stylesheet is
10+
// a CORS request against a null origin with no CORS headers — so the browser
11+
// refuses to apply the CSS. Removing it lets the CSS load from file:// too.
12+
const stripCrossorigin = {
13+
name: 'strip-crossorigin',
14+
transformIndexHtml: {
15+
order: 'post' as const,
16+
handler: (html: string) => html.replace(/\s+crossorigin(=(["'][^"']*["']|\S+))?/g, ''),
17+
},
18+
};
19+
720
export default defineConfig({
821
base: './',
922
plugins: [
1023
nodePolyfills({
11-
// The Spotlight (Spectral) engine pulls in a few Node built-ins.
24+
// The Spectral engine pulls in a few Node built-ins.
1225
globals: { process: true, Buffer: true },
1326
}),
27+
stripCrossorigin,
1428
],
1529
worker: { format: 'es' },
1630
build: { target: 'es2020', sourcemap: false },

0 commit comments

Comments
 (0)