0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Make 'lit' always be bundled in SSR (#3164)

* Make 'lit' always be bundled in SSR

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-04-21 11:12:21 -04:00 committed by GitHub
parent add650a47f
commit e85b16e2b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/lit': patch
---
Fixes lit when running in SSR

View file

@ -40,7 +40,9 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern
let rendererItems = '';
for (const renderer of opts.astroConfig._ctx.renderers) {
const variable = `_renderer${i}`;
imports.push(`import ${variable} from '${renderer.serverEntrypoint}';`);
// Use unshift so that renderers are imported before user code, in case they set globals
// that user code depends on.
imports.unshift(`import ${variable} from '${renderer.serverEntrypoint}';`);
rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`;
i++;
}

View file

@ -27,6 +27,7 @@ describe('Lit integration in SSR', () => {
}
it('Is able to load', async () => {
delete globalThis.window;
const html = await fetchHTML('/');
const $ = cheerioLoad(html);
expect($('#win').text()).to.equal('function');

View file

@ -1,5 +1,5 @@
import { readFileSync } from 'node:fs';
import type { AstroIntegration } from 'astro';
import type { AstroConfig, AstroIntegration } from 'astro';
function getViteConfiguration() {
return {
@ -45,6 +45,19 @@ export default function (): AstroIntegration {
vite: getViteConfiguration(),
});
},
'astro:build:setup': ({ vite, target }) => {
if (target === 'server') {
if(!vite.ssr) {
vite.ssr = {};
}
if(!vite.ssr.noExternal) {
vite.ssr.noExternal = [];
}
if(Array.isArray(vite.ssr.noExternal)) {
vite.ssr.noExternal.push('lit')
}
}
},
},
};
}