From 01193ea7cf7891d79cb319a3d8691e7ec968b670 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 30 Apr 2024 17:11:17 +0100 Subject: [PATCH] feat(vite): support resolving types from vfs --- packages/vite/src/vite.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index a247c181cc..4122b4f550 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -1,10 +1,12 @@ -import { existsSync } from 'node:fs' +import { existsSync, readFileSync, realpathSync } from 'node:fs' import * as vite from 'vite' import { dirname, join, normalize, resolve } from 'pathe' import type { Nuxt, NuxtBuilder, ViteConfig } from '@nuxt/schema' import { addVitePlugin, isIgnored, logger, resolvePath } from '@nuxt/kit' import replace from '@rollup/plugin-replace' +import type { Options as VuePluginOptions } from '@vitejs/plugin-vue' import { sanitizeFilePath } from 'mlly' +import defu from 'defu' import { withoutLeadingSlash } from 'ufo' import { filename } from 'pathe/utils' import { resolveTSConfig } from 'pkg-types' @@ -123,6 +125,16 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { ), } + ctx.config.vue = defu(ctx.config.vue, { + script: { + fs: { + fileExists: file => file in nuxt.vfs || existsSync(file), + readFile: file => nuxt.vfs[file] || readFileSync(file, 'utf-8'), + realpath: path => path in nuxt.vfs ? path : realpathSync(path), + }, + }, + } satisfies VuePluginOptions) + // In build mode we explicitly override any vite options that vite is relying on // to detect whether to inject production or development code (such as HMR code) if (!nuxt.options.dev) {