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 46f5fa0bb..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'); } 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');