Pass user's viteConfig.ssr to the build (#2442)

* Pass user's viteConfig.ssr to the build

* Changeset
This commit is contained in:
Matthew Phillips 2022-01-24 08:55:26 -05:00 committed by GitHub
parent 58136c272f
commit dfe1f8b4e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Allow setting ssr Vite config in the static build

View file

@ -61,7 +61,8 @@
"docs",
"packages/astro/test/fixtures/builtins/packages/*",
"packages/astro/test/fixtures/builtins-polyfillnode",
"packages/astro/test/fixtures/custom-elements/my-component-lib"
"packages/astro/test/fixtures/custom-elements/my-component-lib",
"packages/astro/test/fixtures/static-build/pkg"
],
"volta": {
"node": "14.17.0",

View file

@ -178,7 +178,8 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
envPrefix: 'PUBLIC_',
server: viteConfig.server,
base: astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : '/',
});
ssr: viteConfig.ssr,
} as ViteConfigWithSSR);
}
async function clientBuild(opts: StaticBuildOptions, internals: BuildInternals, input: Set<string>) {

View file

@ -0,0 +1,7 @@
{
"name": "@astrojs/test-static-build",
"version": "0.0.1",
"dependencies": {
"@astrojs/test-static-build-pkg": "file:./pkg"
}
}

View file

@ -0,0 +1,11 @@
{
"name": "@astrojs/test-static-build-pkg",
"main": "./oops.js",
"version": "0.0.1",
"exports": {
".": {
"import": "./pkg.js",
"require": "./oops.js"
}
}
}

View file

@ -0,0 +1 @@
export const test = 'testing';

View file

@ -1,6 +1,7 @@
---
import MainHead from '../components/MainHead.astro';
import Nav from '../components/Nav/index.jsx';
import { test as ssrConfigTest } from '@astrojs/test-static-build-pkg';
let allPosts = await Astro.fetchContent('./posts/*.md');
---
<html>
@ -27,5 +28,6 @@ let allPosts = await Astro.fetchContent('./posts/*.md');
<li><a href={post.url}>post.title</a></li>
))}
</ul>
<div id="ssr-config">{ssrConfigTest}</div>
</body>
</html>

View file

@ -16,6 +16,9 @@ describe('Static build', () => {
buildOptions: {
experimentalStaticBuild: true,
},
ssr: {
noExternal: ['@astrojs/test-static-build-pkg'],
},
});
await fixture.build();
});
@ -94,4 +97,10 @@ describe('Static build', () => {
expect($$(`script[src="${href}"]`).length).to.equal(0, 'no script added to different page');
});
});
it('honors ssr config', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('#ssr-config').text()).to.equal('testing');
});
});