Skip to content

Commit 941db5b

Browse files
committed
refactor: remove advanced raw queries
1 parent 25ce39c commit 941db5b

File tree

10 files changed

+16
-399
lines changed

10 files changed

+16
-399
lines changed

.changeset/fair-pets-crash.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': major
3+
---
4+
5+
Remove experimental "advanced raw queries" feature. Basic `File.svelte?raw` is still supported.

docs/advanced-usage.md

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -63,103 +63,3 @@ The following schemes are supported by vite-plugin-svelte:
6363
//get .svelte file content as a string
6464
import content from 'File.svelte?raw';
6565
```
66-
67-
### experimental
68-
69-
In addition to the plain .svelte source content, you can use special svelte queries.
70-
71-
> These svelte subqueries are experimental, availability, syntax and output format may change
72-
73-
#### raw&svelte
74-
75-
```js
76-
//get output of svelte.preprocess code as string
77-
import preprocessed from 'File.svelte?raw&svelte&type=preprocessed';
78-
```
79-
80-
```js
81-
//get output of svelte.compile js.code as string
82-
import script from 'File.svelte?raw&svelte&type=script';
83-
```
84-
85-
```js
86-
//get output of svelte.compile css.code as string
87-
import style from 'File.svelte?raw&svelte&type=style';
88-
```
89-
90-
##### detail exports
91-
92-
raw&svelte exports code string as default export, but also offers named exports if you need details
93-
94-
```js
95-
//get output of svelte.preprocess
96-
import { code, map, dependencies } from 'File.svelte?raw&svelte&type=preprocessed';
97-
```
98-
99-
```js
100-
//get output of svelte.compile js
101-
import { code, map, dependencies } from 'File.svelte?raw&svelte&type=script';
102-
```
103-
104-
```js
105-
//get output of svelte.compile css
106-
import { code, map, dependencies } from 'File.svelte?raw&svelte&type=style';
107-
```
108-
109-
```js
110-
//get everything in one go
111-
import * as all from 'File.svelte?raw&svelte&type=all';
112-
import {
113-
source,
114-
preprocessed,
115-
dependencies,
116-
js,
117-
css,
118-
ast,
119-
normalizedFilename,
120-
ssr,
121-
lang,
122-
warnings,
123-
stats
124-
} from 'File.svelte?raw&svelte&type=all';
125-
```
126-
127-
#### direct&svelte
128-
129-
```html
130-
<!-- load and execute component script -->
131-
<script type="application/javascript" src="File.svelte?direct&svelte&type=script&lang.js" />
132-
<!-- embed component style as css -->
133-
<link rel="stylesheet" type="text/css" href="File.svelte?direct&svelte&type=style&lang.css" />
134-
```
135-
136-
#### sourcemap
137-
138-
add `&sourcemap` to `?(raw|direct)&svelte&type=(script|style|all)` queries to include sourcemaps (inline for direct)
139-
140-
#### compilerOptions
141-
142-
?raw and ?direct use default compilerOptions, even if you have different values in your svelte.config.js:
143-
144-
```js
145-
const compilerOptions = {
146-
dev: false,
147-
generate: 'client',
148-
css: 'external'
149-
};
150-
```
151-
152-
to get output with different compilerOptions, append them as json like this:
153-
154-
```js
155-
//get ssr output of svelte.compile js as {code, map, dependencies}
156-
import script from 'File.svelte?raw&svelte&type=script&compilerOptions={"generate":"server"}';
157-
```
158-
159-
only a subset of compilerOptions is supported
160-
161-
- generate
162-
- dev
163-
- css
164-
- customElement
165-
- immutable

packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-5/preprocessed.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-5/ssr-preprocessed.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-5/style.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { browserLogs, fetchFromPage, getText, isBuild, testDir } from '~utils';
1+
import { browserLogs, getText, isBuild, testDir } from '~utils';
22
import { createServer, ViteDevServer } from 'vite';
33
import { VERSION } from 'svelte/compiler';
44

@@ -22,114 +22,6 @@ describe('raw', () => {
2222
const result = await getText('#raw');
2323
await expect(result).toMatchFileSnapshot(snapshotFilename('raw'));
2424
});
25-
26-
test('Dummy.svelte?raw&svelte&type=preprocessed', async () => {
27-
const result = await getText('#preprocessed');
28-
await expect(result).toMatchFileSnapshot(snapshotFilename('preprocessed'));
29-
});
30-
31-
test('Dummy.svelte?raw&svelte&type=script', async () => {
32-
const result = await getText('#script');
33-
expect(result).toContain('export default function Dummy');
34-
});
35-
36-
test('Dummy.svelte?raw&svelte&type=script&compilerOptions={"customElement":true}', async () => {
37-
const result = await getText('#wcScript');
38-
expect(result).toContain('$.create_custom_element(Dummy,');
39-
});
40-
41-
test('Dummy.svelte?raw&svelte&type=style', async () => {
42-
const result = await getText('#style');
43-
await expect(result).toMatchFileSnapshot(snapshotFilename('style'));
44-
});
45-
46-
test('Dummy.svelte?raw&svelte&type=all&sourcemap', async () => {
47-
const result = JSON.parse(await getText('#all'));
48-
expect(result.ast).toBeDefined();
49-
expect(result.js).toBeDefined();
50-
expect(result.js.code).toBeDefined();
51-
expect(result.js.map).toBeDefined();
52-
expect(result.css).toBeDefined();
53-
expect(result.css.code).toBeDefined();
54-
expect(result.css.map).toBeDefined();
55-
expect(result.preprocessed).toBeDefined();
56-
expect(result.preprocessed.code).toBeDefined();
57-
expect(result.preprocessed.map).toBeDefined();
58-
});
59-
60-
describe.runIf(!isBuild)('mixed exports', () => {
61-
test('Dummy.svelte?raw&svelte&type=preprocessed', async () => {
62-
const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=preprocessed').then(
63-
(res) => res.text()
64-
);
65-
expect(module).toContain('export const code="<script lang=\\"ts\\">');
66-
expect(module).toContain('export const map={');
67-
expect(module).toContain('export const dependencies=[]');
68-
expect(module).toContain('export default code');
69-
});
70-
test('Dummy.svelte?raw&svelte&type=style', async () => {
71-
const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=style').then((res) =>
72-
res.text()
73-
);
74-
expect(module).toContain('export const code="button.');
75-
expect(module).toContain('export const hasGlobal=false');
76-
expect(module).toContain('export const map={');
77-
expect(module).toContain('export default code');
78-
});
79-
test('Dummy.svelte?raw&svelte&type=script', async () => {
80-
const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=script').then((res) =>
81-
res.text()
82-
);
83-
expect(module).toContain('export const code="import');
84-
expect(module).toContain('export const map={');
85-
expect(module).toContain('export default code');
86-
});
87-
test('Dummy.svelte?raw&svelte&type=all', async () => {
88-
const module = await fetchFromPage('src/Dummy.svelte?raw&svelte&type=all').then((res) =>
89-
res.text()
90-
);
91-
expect(module).toContain('export const ast={"html":');
92-
expect(module).toContain('export const css={"code":"button');
93-
expect(module).toContain('export const dependencies=[]');
94-
expect(module).toContain('export const js={"code":"import ');
95-
expect(module).toContain('export const lang="ts"');
96-
expect(module).toContain('export const metadata={"runes":false}');
97-
expect(module).toContain('export const normalizedFilename="/src/Dummy.svelte"');
98-
expect(module).toContain('export const preprocessed={"code":"<script lang=\\"ts\\">');
99-
expect(module).toContain('export const source="<script lang=\\"ts\\">');
100-
expect(module).toContain('export const ssr=false');
101-
expect(module).toContain('export const warnings=[]');
102-
});
103-
});
104-
});
105-
106-
describe.runIf(!isBuild)('direct', () => {
107-
test('Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css', async () => {
108-
const response = await fetchFromPage(
109-
'src/Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css',
110-
{
111-
headers: { Accept: 'text/css' }
112-
}
113-
);
114-
expect(response.ok).toBe(true);
115-
expect(response.headers.get('Content-Type')).toBe('text/css');
116-
const css = await response.text();
117-
expect(css).toContain('button.');
118-
expect(css).toContain('/*# sourceMappingURL=data');
119-
});
120-
test('Dummy.svelte?direct&svelte&type=script&sourcemap&lang.js', async () => {
121-
const response = await fetchFromPage(
122-
'src/Dummy.svelte?direct&svelte&type=script&sourcemap&lang.js',
123-
{
124-
headers: { Accept: 'text/javascript' }
125-
}
126-
);
127-
expect(response.ok).toBe(true);
128-
expect(response.headers.get('Content-Type')).toMatch(/^(?:text|application)\/javascript$/);
129-
const js = await response.text();
130-
expect(js).toContain('export default function Dummy');
131-
expect(js).toContain('//# sourceMappingURL=data');
132-
});
13325
});
13426

13527
describe.runIf(!isBuild)('ssrLoadModule', () => {
@@ -158,29 +50,4 @@ describe.runIf(!isBuild)('ssrLoadModule', () => {
15850
const result = await ssrLoadDummy('?raw');
15951
await expect(result).toMatchFileSnapshot(snapshotFilename('ssr-raw'));
16052
});
161-
test('?raw&svelte&type=preprocessed', async () => {
162-
const result = await ssrLoadDummy('?raw&svelte&type=preprocessed');
163-
await expect(result).toMatchFileSnapshot(snapshotFilename('ssr-preprocessed'));
164-
});
165-
test('?raw&svelte&type=script', async () => {
166-
const result = await ssrLoadDummy('?raw&svelte&type=script');
167-
expect(result).toContain('export default function Dummy');
168-
});
169-
test('?raw&svelte&type=script&compilerOptions={"customElement":true}', async () => {
170-
const result = await ssrLoadDummy(
171-
'?raw&svelte&type=script&compilerOptions={"customElement":true}'
172-
);
173-
expect(result).toContain('$.create_custom_element(Dummy,');
174-
});
175-
test('?raw&svelte&type=style', async () => {
176-
const result = await ssrLoadDummy('?raw&svelte&type=style');
177-
expect(result).toContain('button.');
178-
});
179-
test('?inline&svelte&type=style&lang.css', async () => {
180-
// Preload Dummy.svelte first so its CSS is processed in the module graph, otherwise loading
181-
// its css inlined url directly will return the raw svelte file rather than the style
182-
await ssrLoadDummy('');
183-
const result = await ssrLoadDummy('?inline&svelte&type=style&lang.css');
184-
expect(result).toContain('button.');
185-
});
18653
});

0 commit comments

Comments
 (0)