Include server CSS in the manifest assets (#3402)

* Include server CSS in the manifest assets

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-05-19 08:38:27 -04:00 committed by GitHub
parent f0aea84920
commit 0c9f770e8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Include server CSS in the SSR manifest assets

View file

@ -69,11 +69,18 @@ if(_start in adapter) {
return void 0;
},
async generateBundle(_opts, bundle) {
const staticFiles = await glob('**/*', {
const staticFiles = new Set(await glob('**/*', {
cwd: fileURLToPath(buildOpts.buildConfig.client),
});
}));
const manifest = buildManifest(buildOpts, internals, staticFiles);
// Add assets from this SSR chunk as well.
for(const [_chunkName, chunk] of Object.entries(bundle)) {
if(chunk.type === 'asset') {
staticFiles.add(chunk.fileName);
}
}
const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles));
await runHookBuildSsr({ config: buildOpts.astroConfig, manifest });
for (const [_chunkName, chunk] of Object.entries(bundle)) {

View file

@ -0,0 +1,19 @@
---
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Astro</title>
<style is:global>
h1 {
color: red;
}
</style>
</head>
<body>
<h1>Astro</h1>
<img src="/puppy.png"/>
</body>
</html>

View file

@ -0,0 +1,27 @@
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';
import testAdapter from './test-adapter.js';
describe('SSR Assets', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-assets/',
experimental: {
ssr: true,
},
adapter: testAdapter(),
});
await fixture.build();
});
it('Do not have to implement getStaticPaths', async () => {
const app = await fixture.loadTestAdapterApp();
/** @type {Set<string>} */
const assets = app.manifest.assets;
expect(assets.size).to.equal(1);
expect(Array.from(assets)[0].endsWith('.css')).to.be.true;
});
});

View file

@ -137,8 +137,10 @@ export async function loadFixture(inlineConfig) {
clean: () => fs.promises.rm(config.outDir, { maxRetries: 10, recursive: true, force: true }),
loadTestAdapterApp: async () => {
const url = new URL('./server/entry.mjs', config.outDir);
const { createApp } = await import(url);
return createApp();
const { createApp, manifest } = await import(url);
const app =createApp();
app.manifest = manifest;
return app;
},
editFile: async (filePath, newContents) => {
const fileUrl = new URL(filePath.replace(/^\//, ''), config.root);