Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't transform raw imports (fixes #87) #88

Merged
merged 2 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-donkeys-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

do not transform imports tagged with ?url or ?raw (fixes #87)
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function svelte(inlineOptions?: Partial<Options>): 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');
}
Expand Down
7 changes: 5 additions & 2 deletions packages/vite-plugin-svelte/src/utils/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ 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<keyof RequestQuery>) {
if (query[p] != null) {
// @ts-ignore
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');

Expand Down