-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(astrojs/cloudflare): add support for
splitted
SSR bundles (#…
…7464) * initial commit * try to fix windows * output files directly into the correct folder * allow for rest parameters * use fixed hook * improve tests * apply doc's team suggestions for README Co-authored-by: Sarah Rainsberger <[email protected]> * try to fix prerendering * apply doc's team suggestion for changeset Co-authored-by: Sarah Rainsberger <[email protected]> * bump to minor * readme update * resolve review comments * optimize memory allocation * resolve review comments * add removed link, to make sure old docs keep same * resolve comment Co-authored-by: Sarah Rainsberger <[email protected]> --------- Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]>
- Loading branch information
Showing
16 changed files
with
338 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@astrojs/cloudflare': minor | ||
--- | ||
|
||
Split Support in Cloudflare | ||
|
||
Adds support for configuring `build.split` when using the Cloudflare adapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/integrations/cloudflare/test/directory-split.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { loadFixture } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
import cloudflare from '../dist/index.js'; | ||
|
||
/** @type {import('./test-utils').Fixture} */ | ||
describe('Cloudflare SSR split', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/split/', | ||
adapter: cloudflare({ mode: 'directory' }), | ||
output: "server", | ||
build: { | ||
split: true, | ||
excludeMiddleware: false | ||
}, | ||
vite: { | ||
build: { | ||
minify: false, | ||
}, | ||
}, | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
after(() => { | ||
fixture.clean(); | ||
}); | ||
|
||
it('generates functions folders inside the project root, and checks that each page is emitted by astro', async () => { | ||
expect(await fixture.pathExists('../functions')).to.be.true; | ||
expect(await fixture.pathExists('../functions/index.js')).to.be.true; | ||
expect(await fixture.pathExists('../functions/blog/cool.js')).to.be.true; | ||
expect(await fixture.pathExists('../functions/blog/[post].js')).to.be.true; | ||
expect(await fixture.pathExists('../functions/[person]/[car].js')).to.be.true; | ||
expect(await fixture.pathExists('../functions/files/[[path]].js')).to.be.true; | ||
expect(await fixture.pathExists('../functions/[language]/files/[[path]].js')).to.be.true; | ||
}); | ||
|
||
it('generates pre-rendered files', async () => { | ||
expect(await fixture.pathExists('./prerender/index.html')).to.be.true; | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/integrations/cloudflare/test/fixtures/split/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/astro-cloudflare-split", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/cloudflare": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/integrations/cloudflare/test/fixtures/split/src/middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineMiddleware } from "astro/middleware"; | ||
|
||
export const onRequest = defineMiddleware(({ locals, request }, next) => { | ||
// intercept response data from a request | ||
// optionally, transform the response by modifying `locals` | ||
locals.title = "New title" | ||
|
||
// return a Response or the result of calling `next()` | ||
return next() | ||
}); |
37 changes: 37 additions & 0 deletions
37
...es/integrations/cloudflare/test/fixtures/split/src/pages/[language]/files/[...path].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
const files = [ | ||
{ | ||
slug: undefined, | ||
title: 'Root level', | ||
}, | ||
{ | ||
slug: 'test.png', | ||
title: "One level" | ||
}, | ||
{ | ||
slug: 'assets/test.png', | ||
title: "Two levels" | ||
}, | ||
{ | ||
slug: 'assets/images/test.png', | ||
title: 'Three levels', | ||
} | ||
]; | ||
const { path } = Astro.params; | ||
const page = files.find((page) => page.slug === path); | ||
const { title } = page; | ||
--- | ||
<html> | ||
<body> | ||
<h1>Files / Rest Parameters / {title}</h1> | ||
<p>DEBUG: {path} </p> | ||
<p><a href="/">index</a></p> | ||
</body> | ||
<style> | ||
h1 { | ||
background-color: yellow; | ||
} | ||
</style> | ||
</html> |
14 changes: 14 additions & 0 deletions
14
packages/integrations/cloudflare/test/fixtures/split/src/pages/[person]/[car].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
const { person, car } = Astro.params; | ||
--- | ||
<html> | ||
<body> | ||
<h1> {person} / {car}</h1> | ||
<p><a href="/">index</a></p> | ||
</body> | ||
<style> | ||
h1 { | ||
background-color: blue; | ||
} | ||
</style> | ||
</html> |
14 changes: 14 additions & 0 deletions
14
packages/integrations/cloudflare/test/fixtures/split/src/pages/blog/[post].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
const { post } = Astro.params; | ||
--- | ||
<html> | ||
<body> | ||
<h1>Blog / {post}</h1> | ||
<p><a href="/">index</a></p> | ||
</body> | ||
<style> | ||
h1 { | ||
background-color: pink; | ||
} | ||
</style> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
packages/integrations/cloudflare/test/fixtures/split/src/pages/blog/cool.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<body> | ||
<h1>Blog / Cool</h1> | ||
<p><a href="/">index</a></p> | ||
</body> | ||
<style> | ||
h1 { | ||
background-color: orange; | ||
} | ||
</style> | ||
</html> |
Oops, something went wrong.