mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 22:55:13 +00:00
fix(vite): omit css ?raw
from head when in dev mode (#27940)
This commit is contained in:
parent
5ac6aa574a
commit
0f684970e9
@ -8,7 +8,7 @@ import { normalizeViteManifest } from 'vue-bundle-renderer'
|
|||||||
import type { Manifest } from 'vue-bundle-renderer'
|
import type { Manifest } from 'vue-bundle-renderer'
|
||||||
import type { ViteBuildContext } from './vite'
|
import type { ViteBuildContext } from './vite'
|
||||||
|
|
||||||
export async function writeManifest (ctx: ViteBuildContext, css: string[] = []) {
|
export async function writeManifest (ctx: ViteBuildContext) {
|
||||||
// Write client manifest for use in vue-bundle-renderer
|
// Write client manifest for use in vue-bundle-renderer
|
||||||
const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client')
|
const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client')
|
||||||
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')
|
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')
|
||||||
@ -17,7 +17,7 @@ export async function writeManifest (ctx: ViteBuildContext, css: string[] = [])
|
|||||||
'@vite/client': {
|
'@vite/client': {
|
||||||
isEntry: true,
|
isEntry: true,
|
||||||
file: '@vite/client',
|
file: '@vite/client',
|
||||||
css,
|
css: [],
|
||||||
module: true,
|
module: true,
|
||||||
resourceType: 'script',
|
resourceType: 'script',
|
||||||
},
|
},
|
||||||
|
@ -6,6 +6,7 @@ import { isAbsolute, normalize, resolve } from 'pathe'
|
|||||||
import { addDevServerHandler } from '@nuxt/kit'
|
import { addDevServerHandler } from '@nuxt/kit'
|
||||||
import { isFileServingAllowed } from 'vite'
|
import { isFileServingAllowed } from 'vite'
|
||||||
import type { ModuleNode, Plugin as VitePlugin } from 'vite'
|
import type { ModuleNode, Plugin as VitePlugin } from 'vite'
|
||||||
|
import { getQuery } from 'ufo'
|
||||||
import { normalizeViteManifest } from 'vue-bundle-renderer'
|
import { normalizeViteManifest } from 'vue-bundle-renderer'
|
||||||
import { resolve as resolveModule } from 'mlly'
|
import { resolve as resolveModule } from 'mlly'
|
||||||
import { distDir } from './dirs'
|
import { distDir } from './dirs'
|
||||||
@ -78,13 +79,23 @@ export function registerViteNodeMiddleware (ctx: ViteBuildContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getManifest (ctx: ViteBuildContext) {
|
function getManifest (ctx: ViteBuildContext) {
|
||||||
const css = Array.from(ctx.ssrServer!.moduleGraph.urlToModuleMap.keys())
|
const css = new Set<string>()
|
||||||
.filter(i => isCSS(i))
|
for (const key of ctx.ssrServer!.moduleGraph.urlToModuleMap.keys()) {
|
||||||
|
if (isCSS(key)) {
|
||||||
|
const query = getQuery(key)
|
||||||
|
if ('raw' in query) { continue }
|
||||||
|
const importers = ctx.ssrServer!.moduleGraph.urlToModuleMap.get(key)?.importers
|
||||||
|
if (importers && [...importers].every(i => i.id && 'raw' in getQuery(i.id))) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
css.add(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const manifest = normalizeViteManifest({
|
const manifest = normalizeViteManifest({
|
||||||
'@vite/client': {
|
'@vite/client': {
|
||||||
file: '@vite/client',
|
file: '@vite/client',
|
||||||
css,
|
css: [...css],
|
||||||
module: true,
|
module: true,
|
||||||
isEntry: true,
|
isEntry: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user