Fix Svelte and Vue styles in dev (#1933)

This commit is contained in:
Drew Powers 2021-11-19 13:53:44 -07:00 committed by GitHub
parent 684367b7bf
commit 16fa615d34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,8 @@ import { injectTags } from './html.js';
import { generatePaginateFunction } from './paginate.js';
import { getParams, validateGetStaticPathsModule, validateGetStaticPathsResult } from './routing.js';
const svelteAndVueStylesRE = /\?[^&]+&type=style&lang/;
interface SSROptions {
/** an instance of the AstroConfig */
astroConfig: AstroConfig;
@ -245,15 +247,23 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
// inject CSS
[...getStylesForURL(filePath, viteServer)].forEach((href) => {
tags.push({
tag: 'link',
attrs: {
rel: 'stylesheet',
href,
'data-astro-injected': true,
},
injectTo: 'head',
});
if (mode === 'development' && svelteAndVueStylesRE.test(href)) {
tags.push({
tag: 'script',
attrs: { type: 'module', src: href },
injectTo: 'head',
});
} else {
tags.push({
tag: 'link',
attrs: {
rel: 'stylesheet',
href,
'data-astro-injected': true,
},
injectTo: 'head',
});
}
});
// add injected tags