chore(vite): restore utils required for dev-bundler

This commit is contained in:
Daniel Roe 2024-06-24 23:50:37 +02:00
parent 7abd982f85
commit e3448fa0da
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 12 additions and 2 deletions

View File

@ -1,11 +1,11 @@
import { pathToFileURL } from 'node:url'
import { existsSync } from 'node:fs'
import { writeFile } from 'node:fs/promises'
import { builtinModules } from 'node:module'
import { isAbsolute, normalize, resolve } from 'pathe'
import type * as vite from 'vite'
import type { isExternal } from 'externality'
import { genDynamicImport, genObjectFromRawEntries } from 'knitwork'
import fse from 'fs-extra'
import { debounce } from 'perfect-debounce'
import { isIgnored, logger } from '@nuxt/kit'
import { hashId, isCSS, uniq } from './utils'
@ -236,7 +236,7 @@ export async function initViteDevBundler (ctx: ViteBuildContext, onBuild: () =>
const _doBuild = async () => {
const start = Date.now()
const { code, ids } = await bundleRequest(options, ctx.entry)
await fse.writeFile(resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'), code, 'utf-8')
await writeFile(resolve(ctx.nuxt.options.buildDir, 'dist/server/server.mjs'), code, 'utf-8')
// Have CSS in the manifest to prevent FOUC on dev SSR
const manifestIds: string[] = []
for (const i of ids) {

View File

@ -1,5 +1,11 @@
import { hash } from 'ohash'
export { isVue } from '../../../nuxt/src/core/utils/plugins'
export function uniq<T> (arr: T[]): T[] {
return Array.from(new Set(arr))
}
// Copied from vue-bundle-renderer utils
const IS_CSS_RE = /\.(?:css|scss|sass|postcss|pcss|less|stylus|styl)(?:\?[^.]+)?$/
@ -7,6 +13,10 @@ export function isCSS (file: string) {
return IS_CSS_RE.test(file)
}
export function hashId (id: string) {
return '$id_' + hash(id)
}
export function matchWithStringOrRegex (value: string, matcher: string | RegExp) {
if (typeof matcher === 'string') {
return value === matcher