Pass user's viteConfig.ssr to the build (#2442)
* Pass user's viteConfig.ssr to the build * Changeset
This commit is contained in:
parent
58136c272f
commit
dfe1f8b4e7
8 changed files with 39 additions and 2 deletions
5
.changeset/neat-seals-fold.md
Normal file
5
.changeset/neat-seals-fold.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Allow setting ssr Vite config in the static build
|
|
@ -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",
|
||||
|
|
|
@ -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>) {
|
||||
|
|
7
packages/astro/test/fixtures/static-build/package.json
vendored
Normal file
7
packages/astro/test/fixtures/static-build/package.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@astrojs/test-static-build",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@astrojs/test-static-build-pkg": "file:./pkg"
|
||||
}
|
||||
}
|
11
packages/astro/test/fixtures/static-build/pkg/package.json
vendored
Normal file
11
packages/astro/test/fixtures/static-build/pkg/package.json
vendored
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
1
packages/astro/test/fixtures/static-build/pkg/pkg.js
vendored
Normal file
1
packages/astro/test/fixtures/static-build/pkg/pkg.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export const test = 'testing';
|
|
@ -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>
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue