Skip to content

Commit 847077d

Browse files
authored
feat: improve useVitePreprocess (#173)
* feat: improve useVitePreprocess * refactor(preprocessor): remove unneeded checks * refactor(preprocessor): clean code * fix: typo * refactor: use esbuild types * refactor: again * chore: upgrade vite * chore: add changeset * fix(preprocess): fix vite css sourcemaps * fix: typo * fix: typo 2 * fix: typo 3 * fix: typo 4 * chore: update preprocess caveat text * perf: improve preprocessor lang check
1 parent 50ad738 commit 847077d

File tree

17 files changed

+111
-78
lines changed

17 files changed

+111
-78
lines changed

.changeset/large-frogs-lick.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+
Use transformWithEsbuild for vite script preprocessor
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getColor, getText } from 'testUtils';
2+
3+
test('should render App', async () => {
4+
expect(await getText('h1.foo')).toBe(`Hello world`);
5+
expect(await getColor('#app-scss')).toBe('rgb(0, 0, 153)'); // darken($blue, 20)
6+
expect(await getText('#foo-title')).toBe('Styles with stylus blub');
7+
expect(await getColor('#foo-title')).toBe('magenta');
8+
expect(await getColor('p.note')).toBe('rgb(255, 62, 0)');
9+
});

packages/playground/preprocess-with-vite/index.html renamed to packages/e2e-tests/preprocess-with-vite/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<title>Svelte App</title>
88
</head>
99
<body>
10-
<script type="module" src="/src/index.js"></script>
10+
<script type="module" src="/src/index.ts"></script>
1111
</body>
1212
</html>

packages/playground/preprocess-with-vite/package.json renamed to packages/e2e-tests/preprocess-with-vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "playground-preprocess-with-vite",
2+
"name": "e2e-tests-preprocess-with-vite",
33
"private": true,
44
"version": "0.0.0",
55
"scripts": {
66
"dev": "vite",
77
"build": "vite build",
8-
"serve": "vite preview"
8+
"preview": "vite preview"
99
},
1010
"devDependencies": {
1111
"@sveltejs/vite-plugin-svelte": "workspace:*",

packages/playground/preprocess-with-vite/src/App.svelte renamed to packages/e2e-tests/preprocess-with-vite/src/App.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script lang="ts">
22
import Foo from './Foo.svelte';
33
import Bar from './Bar.svelte';
4+
export let hello: string;
45
const world: string = 'world'; // edit world and save to see hmr update
56
</script>
67

7-
<h1 class="foo">Hello {world}</h1>
8-
<p>This is styled with scss using darken fn</p>
8+
<h1 class="foo">{hello} {world}</h1>
9+
<p id="app-scss">This is styled with scss using darken fn</p>
910
<Foo />
1011
<Bar />
1112

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import BarChild from './BarChild.svelte';
3+
</script>
4+
5+
<BarChild />
6+
7+
<style>
8+
/*
9+
should warn because style tag only contains unscoped styles
10+
(code smell & affects css hmr)
11+
*/
12+
:global(.note) {
13+
background-color: lightblue;
14+
}
15+
</style>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Bar child</p>

packages/playground/preprocess-with-vite/src/Foo.svelte renamed to packages/e2e-tests/preprocess-with-vite/src/Foo.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export let bla: string = 'blub';
44
</script>
55

6-
<h1>Styles with {foo} {bla}</h1>
6+
<h1 id="foo-title">Styles with {foo} {bla}</h1>
77
<p class="note">cool, huh?</p>
88

99
<style lang="stylus">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import App from './App.svelte';
2+
import { Hello } from './types';
3+
4+
const hello: Hello = 'Hello';
5+
6+
const app = new App({
7+
target: document.body,
8+
props: {
9+
hello
10+
}
11+
});
12+
13+
export default app;

0 commit comments

Comments
 (0)