From 0ad223c9fb976018189faf74b9a7c36e4c2f320d Mon Sep 17 00:00:00 2001 From: Matt Jennings Date: Thu, 8 Jul 2021 22:34:44 -0500 Subject: [PATCH 1/2] fix: don't transform raw imports (fixes #87) --- packages/vite-plugin-svelte/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite-plugin-svelte/src/index.ts b/packages/vite-plugin-svelte/src/index.ts index 46f5fa0bb..b4da315eb 100644 --- a/packages/vite-plugin-svelte/src/index.ts +++ b/packages/vite-plugin-svelte/src/index.ts @@ -153,7 +153,7 @@ export function svelte(inlineOptions?: Partial): Plugin { async transform(code, id, ssr) { const svelteRequest = requestParser(id, !!ssr); - if (!svelteRequest) { + if (!svelteRequest || svelteRequest.query.raw) { return; } const { filename, query } = svelteRequest; From ca7bab9da952e6b0249dd73db91b3acb2056f478 Mon Sep 17 00:00:00 2001 From: dominikg Date: Fri, 9 Jul 2021 19:18:10 +0200 Subject: [PATCH 2/2] improve fix implementation and add changeset --- .changeset/breezy-donkeys-argue.md | 5 +++++ packages/vite-plugin-svelte/src/index.ts | 4 ++-- packages/vite-plugin-svelte/src/utils/id.ts | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changeset/breezy-donkeys-argue.md diff --git a/.changeset/breezy-donkeys-argue.md b/.changeset/breezy-donkeys-argue.md new file mode 100644 index 000000000..5f2073d55 --- /dev/null +++ b/.changeset/breezy-donkeys-argue.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +do not transform imports tagged with ?url or ?raw (fixes #87) diff --git a/packages/vite-plugin-svelte/src/index.ts b/packages/vite-plugin-svelte/src/index.ts index b4da315eb..74ce3e304 100644 --- a/packages/vite-plugin-svelte/src/index.ts +++ b/packages/vite-plugin-svelte/src/index.ts @@ -93,7 +93,7 @@ export function svelte(inlineOptions?: Partial): Plugin { } } // prevent vite asset plugin from loading files as url that should be compiled in transform - if (!query.url && !query.raw && viteConfig.assetsInclude(filename)) { + if (viteConfig.assetsInclude(filename)) { log.debug(`load returns raw content for ${filename}`); return fs.readFileSync(filename, 'utf-8'); } @@ -153,7 +153,7 @@ export function svelte(inlineOptions?: Partial): Plugin { async transform(code, id, ssr) { const svelteRequest = requestParser(id, !!ssr); - if (!svelteRequest || svelteRequest.query.raw) { + if (!svelteRequest) { return; } const { filename, query } = svelteRequest; diff --git a/packages/vite-plugin-svelte/src/utils/id.ts b/packages/vite-plugin-svelte/src/utils/id.ts index d80747be7..ef9f51aa8 100644 --- a/packages/vite-plugin-svelte/src/utils/id.ts +++ b/packages/vite-plugin-svelte/src/utils/id.ts @@ -43,7 +43,7 @@ function parseToSvelteRequest( root: string, timestamp: number, ssr: boolean -): SvelteRequest { +): SvelteRequest | undefined { const query: RequestQuery = qs.parse(rawQuery) as RequestQuery; for (const p of ['svelte', 'url', 'raw'] as Array) { if (query[p] != null) { @@ -51,7 +51,10 @@ function parseToSvelteRequest( query[p] = true; } } - + if (query.url || query.raw) { + // skip requests with special vite tags + return; + } const normalizedFilename = normalize(filename, root); const cssId = createVirtualImportId(filename, root, 'style');