Skip to content

Commit 8fd2058

Browse files
committed
feat: support ?inline query on svelte style virtual modules
1 parent da54670 commit 8fd2058

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

.changeset/sixty-chefs-relate.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': minor
3+
---
4+
5+
Support `?inline` query on Svelte style virtual modules
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
button.svelte-d8vj6a {
2+
color: #000099;
3+
}

packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,11 @@ describe.runIf(!isBuild)('ssrLoadModule', () => {
162162
const result = await ssrLoadDummy('?raw&svelte&type=style');
163163
await expect(result).toMatchFileSnapshot(snapshotFilename('ssr-style'));
164164
});
165+
test('?inline&svelte&type=style&lang.css', async () => {
166+
// Preload Dummy.svelte first so its CSS is processed in the module graph, otherwise loading
167+
// its css inlined url directly will return the raw svelte file rather than the style
168+
await ssrLoadDummy('');
169+
const result = await ssrLoadDummy('?inline&svelte&type=style&lang.css');
170+
await expect(result).toMatchFileSnapshot(snapshotFilename('ssr-inline-style'));
171+
});
165172
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function svelte(inlineOptions) {
124124
const ssr = !!opts?.ssr;
125125
const svelteRequest = requestParser(importee, ssr);
126126
if (svelteRequest?.query.svelte) {
127-
if (svelteRequest.query.type === 'style' && !svelteRequest.raw) {
127+
if (svelteRequest.query.type === 'style' && !svelteRequest.raw && !svelteRequest.inline) {
128128
// return cssId with root prefix so postcss pipeline of vite finds the directory correctly
129129
// see https://github.com/sveltejs/vite-plugin-svelte/issues/14
130130
log.debug(

packages/vite-plugin-svelte/src/types/id.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface RequestQuery {
1515
url?: boolean;
1616
raw?: boolean;
1717
direct?: boolean;
18+
inline?: boolean;
1819
}
1920

2021
export interface SvelteRequest {
@@ -26,6 +27,7 @@ export interface SvelteRequest {
2627
timestamp: number;
2728
ssr: boolean;
2829
raw: boolean;
30+
inline: boolean;
2931
}
3032

3133
export interface SvelteModuleRequest {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ function parseToSvelteRequest(id, filename, rawQuery, root, timestamp, ssr) {
5050
query,
5151
timestamp,
5252
ssr,
53-
raw
53+
raw,
54+
inline: !!query.inline
5455
};
5556
}
5657

0 commit comments

Comments
 (0)