feat: Cloudflare Pages support for hosting#2570
Conversation
Auto-detect wrangler.toml or wrangler.json and generate a _headers file with long-term caching for /assets/*. Update _redirects output for SPA and add Cloudflare Pages docs and local Wrangler preview examples.
✅ Deploy Preview for slidev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@slidev/client
create-slidev
create-slidev-theme
@slidev/parser
@slidev/cli
@slidev/types
commit: |
There was a problem hiding this comment.
Pull request overview
Adds first-class Cloudflare Pages guidance and output tweaks so Slidev-built decks work well on Cloudflare Pages (SPA redirects + long-term caching for hashed assets).
Changes:
- Document Cloudflare Pages deployment + local preview via Wrangler in both the main hosting guide and skills reference docs.
- Update generated
_redirectsoutput to include an explicitindex.htmlrule plus SPA fallback. - Auto-detect
wrangler.toml/wrangler.jsonand generate a_headersfile to set long-term caching on/assets/*.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| skills/slidev/references/core-hosting.md | Adds Cloudflare Pages deployment + Wrangler local preview instructions. |
| packages/slidev/node/commands/build.ts | Updates _redirects generation and adds Cloudflare Pages _headers generation when Wrangler config is present. |
| docs/guide/hosting.md | Adds Cloudflare Pages section and explains the generated _redirects / _headers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const base = config.base | ||
| await fs.writeFile( | ||
| redirectsPath, | ||
| `${base}index.html ${base}index.html 200\n${base}* ${base}index.html 200\n`, |
There was a problem hiding this comment.
The generated _redirects file includes a rule rewriting ${base}index.html to itself. This doesn’t add behavior beyond the ${base}* -> ${base}index.html SPA fallback (which already covers requests for ${base}index.html) and makes the output more verbose than necessary. Consider dropping the no-op index.html -> index.html rule and keeping only the SPA fallback rule.
| `${base}index.html ${base}index.html 200\n${base}* ${base}index.html 200\n`, | |
| `${base}* ${base}index.html 200\n`, |
| if (hasWranglerConfig) { | ||
| const headersPath = resolve(outDir, '_headers') | ||
| if (!existsSync(headersPath)) { | ||
| await fs.writeFile(headersPath, `\n/assets/*\n Cache-Control: public, max-age=31536000, immutable\n`, 'utf-8') |
There was a problem hiding this comment.
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') |
|
|
||
| Slidev automatically detects when you are deploying to [Cloudflare Pages](https://pages.cloudflare.com/) by looking for a `wrangler.toml` or `wrangler.json` file in your project root. | ||
|
|
||
| When detected, Slidev generates the necessary `_redirects` and `_headers` files for optimal SPA hosting. |
There was a problem hiding this comment.
This paragraph implies _redirects generation is conditional on Cloudflare Pages detection, but _redirects is generated unconditionally during slidev build (only skipped if the file already exists). Consider rephrasing to say that detection adds _headers generation, while _redirects is generated for SPA hosting in general.
| When detected, Slidev generates the necessary `_redirects` and `_headers` files for optimal SPA hosting. | |
| For SPA hosting, Slidev generates the necessary `_redirects` file during `slidev build` (unless it already exists). When Cloudflare Pages is detected, Slidev also generates the `_headers` file for optimal deployment. |
Auto-detect wrangler.toml or wrangler.json and generate a _headers file with long-term caching for /assets/*.
Update _redirects output for SPA and add Cloudflare Pages docs and local Wrangler preview examples.