From 08ae70e5e18ad3a73228c2db121c33d4d5d737a1 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:20:42 -0400 Subject: [PATCH] wip --- packages/vite/src/node/plugins/asset.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index c018ba56427fce..aa74edf5b99c42 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -137,7 +137,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { // will fail to resolve in the main resolver. handle them here. const publicFile = checkPublicFile(id, config) if (publicFile) { - return id + return { id: publicFile, meta: { publicUrl: id } } } }, @@ -148,15 +148,18 @@ export function assetPlugin(config: ResolvedConfig): Plugin { return } + const moduleInfo = this.getModuleInfo(id) + const meta = (moduleInfo?.meta || {}) as { publicUrl?: string } + // raw requests, read from disk - if (rawRE.test(id)) { - const file = checkPublicFile(id, config) || cleanUrl(id) - // raw query, read file and return as string + if (rawRE.test(meta.publicUrl || id)) { + const file = meta.publicUrl ? id : cleanUrl(id) return `export default ${JSON.stringify( await fsp.readFile(file, 'utf-8') )}` } + id = meta.publicUrl || id if (!config.assetsInclude(cleanUrl(id)) && !urlRE.test(id)) { return }