fix(nuxt): always inline entry styles (#7386)

This commit is contained in:
Daniel Roe 2022-09-10 10:43:17 +01:00 committed by GitHub
parent e60d03b940
commit 83949c3734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -224,7 +224,7 @@ function renderHTMLDocument (html: NuxtRenderHTMLContext) {
async function renderInlineStyles (usedModules: Set<string> | string[]) { async function renderInlineStyles (usedModules: Set<string> | string[]) {
const styleMap = await getSSRStyles() const styleMap = await getSSRStyles()
const inlinedStyles = new Set<string>() const inlinedStyles = new Set<string>()
for (const mod of usedModules) { for (const mod of ['entry', ...usedModules]) {
if (mod in styleMap) { if (mod in styleMap) {
for (const style of await styleMap[mod]()) { for (const style of await styleMap[mod]()) {
inlinedStyles.add(`<style>${style}</style>`) inlinedStyles.add(`<style>${style}</style>`)

View File

@ -60,11 +60,11 @@ export function ssrStylesPlugin (options: SSRStylePluginOptions): Plugin {
source: source:
[ [
...globalStylesArray.map((css, i) => `import style_${i} from './${css}';`), ...globalStylesArray.map((css, i) => `import style_${i} from './${css}';`),
`const globalStyles = [${globalStylesArray.map((_, i) => `style_${i}`).join(', ')}]`, 'const interopDefault = r => r.default || r || []',
'const resolveStyles = r => globalStyles.concat(r.default || r || [])', `export default ${genObjectFromRawEntries([
`export default ${genObjectFromRawEntries( ['entry', `() => [${globalStylesArray.map((_, i) => `style_${i}`).join(', ')}]`],
Object.entries(emitted).map(([key, value]) => [key, `() => import('./${this.getFileName(value)}').then(resolveStyles)`]) ...Object.entries(emitted).map(([key, value]) => [key, `() => import('./${this.getFileName(value)}').then(interopDefault)`]) as [string, string][]
)}` ])}`
].join('\n') ].join('\n')
}) })
}, },