-
-
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.
* Expose the ssr manifest * Add changeset * Add types for virtual mod
- Loading branch information
Showing
10 changed files
with
102 additions
and
1 deletion.
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,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Expose the manifest to plugins via the astro:ssr-manifest virtual module |
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
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,26 @@ | ||
|
||
import type { Plugin as VitePlugin } from 'vite'; | ||
|
||
const manifestVirtualModuleId = 'astro:ssr-manifest'; | ||
const resolvedManifestVirtualModuleId = '\0' + manifestVirtualModuleId; | ||
|
||
export function vitePluginSSRManifest(): VitePlugin { | ||
return { | ||
name: '@astrojs/vite-plugin-astro-ssr-manifest', | ||
enforce: 'post', | ||
resolveId(id, parent) { | ||
if(id === manifestVirtualModuleId) { | ||
return resolvedManifestVirtualModuleId; | ||
} | ||
}, | ||
load(id) { | ||
if (id === resolvedManifestVirtualModuleId) { | ||
return `export let manifest = {}; | ||
export function _privateSetManifestDontUseThis(ssrManifest) { | ||
manifest = ssrManifest; | ||
}`; | ||
} | ||
return void 0; | ||
}, | ||
}; | ||
} |
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,8 @@ | ||
{ | ||
"name": "@test/ssr-manifest", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/astro/test/fixtures/ssr-manifest/src/pages/index.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,17 @@ | ||
--- | ||
import { manifest } from 'astro:ssr-manifest'; | ||
--- | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
<style> | ||
body { | ||
background: green; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Testing</h1> | ||
<div id="assets" set:html={JSON.stringify([...manifest.assets])}></div> | ||
</body> | ||
</html> |
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,30 @@ | ||
|
||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
import testAdapter from './test-adapter.js'; | ||
import * as cheerio from 'cheerio'; | ||
|
||
describe('astro:ssr-manifest', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/ssr-manifest/', | ||
output: 'server', | ||
adapter: testAdapter(), | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('works', async () => { | ||
const app = await fixture.loadTestAdapterApp(); | ||
const request = new Request('http://example.com/'); | ||
const response = await app.render(request); | ||
const html = await response.text(); | ||
|
||
const $ = cheerio.load(html); | ||
expect($('#assets').text()).to.equal('["/_astro/index.1bad7273.css"]'); | ||
|
||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.