Skip to content

Commit d1d2638

Browse files
fix: don't transform raw imports (fixes #87) (#88)
* fix: don't transform raw imports (fixes #87) * improve fix implementation and add changeset Co-authored-by: dominikg <dominik.goepel@gmx.de>
1 parent 9a44775 commit d1d2638

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.changeset/breezy-donkeys-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
do not transform imports tagged with ?url or ?raw (fixes #87)

packages/vite-plugin-svelte/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
9393
}
9494
}
9595
// prevent vite asset plugin from loading files as url that should be compiled in transform
96-
if (!query.url && !query.raw && viteConfig.assetsInclude(filename)) {
96+
if (viteConfig.assetsInclude(filename)) {
9797
log.debug(`load returns raw content for ${filename}`);
9898
return fs.readFileSync(filename, 'utf-8');
9999
}

packages/vite-plugin-svelte/src/utils/id.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ function parseToSvelteRequest(
4343
root: string,
4444
timestamp: number,
4545
ssr: boolean
46-
): SvelteRequest {
46+
): SvelteRequest | undefined {
4747
const query: RequestQuery = qs.parse(rawQuery) as RequestQuery;
4848
for (const p of ['svelte', 'url', 'raw'] as Array<keyof RequestQuery>) {
4949
if (query[p] != null) {
5050
// @ts-ignore
5151
query[p] = true;
5252
}
5353
}
54-
54+
if (query.url || query.raw) {
55+
// skip requests with special vite tags
56+
return;
57+
}
5558
const normalizedFilename = normalize(filename, root);
5659
const cssId = createVirtualImportId(filename, root, 'style');
5760

0 commit comments

Comments
 (0)