-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: Cloudflare Pages support for hosting #2570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -126,10 +126,26 @@ export async function build( | |||||
|
|
||||||
| // copy index.html to 404.html for GitHub Pages | ||||||
| await fs.copyFile(resolve(outDir, 'index.html'), resolve(outDir, '404.html')) | ||||||
| // _redirects for SPA | ||||||
|
|
||||||
| // _redirects for SPA (supported by Netlify and Cloudflare Pages) | ||||||
| const redirectsPath = resolve(outDir, '_redirects') | ||||||
| if (!existsSync(redirectsPath)) | ||||||
| await fs.writeFile(redirectsPath, `${config.base}* ${config.base}index.html 200\n`, 'utf-8') | ||||||
| if (!existsSync(redirectsPath)) { | ||||||
| const base = config.base | ||||||
| await fs.writeFile( | ||||||
| redirectsPath, | ||||||
| `${base}index.html ${base}index.html 200\n${base}* ${base}index.html 200\n`, | ||||||
|
||||||
| `${base}index.html ${base}index.html 200\n${base}* ${base}index.html 200\n`, | |
| `${base}* ${base}index.html 200\n`, |
Copilot
AI
Apr 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated _headers rule is hard-coded to /assets/*. If config.base is set for subdirectory deployments (e.g. /my-slides/), requests will be under ${config.base}assets/... and this rule won’t match, so the long-term caching won’t apply. Consider prefixing the pattern with config.base (e.g. ${config.base}assets/*) and dropping the initial blank line in the file content.
| await fs.writeFile(headersPath, `\n/assets/*\n Cache-Control: public, max-age=31536000, immutable\n`, 'utf-8') | |
| await fs.writeFile(headersPath, `${config.base}assets/*\n Cache-Control: public, max-age=31536000, immutable\n`, 'utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph implies
_redirectsgeneration is conditional on Cloudflare Pages detection, but_redirectsis generated unconditionally duringslidev build(only skipped if the file already exists). Consider rephrasing to say that detection adds_headersgeneration, while_redirectsis generated for SPA hosting in general.