Skip to content

Commit 93d3a49

Browse files
committed
token shaker and other style tweaks
1 parent f724115 commit 93d3a49

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed

src/routes/docs/detailed-walkthrough/+page.svelte

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@
108108
<span class="theme-defined">Colors</span>, the
109109
<code class="theme-defined">--m3c-</code> variables, are also tokens.
110110
</p>
111-
<p>
112-
We recommend using <a href="https://www.npmjs.com/package/vite-plugin-token-shaker"
113-
>vite-plugin-token-shaker</a
114-
> to minify tokens by dropping unused ones, inlining rarely used ones, and mangling commonly used ones.
115-
</p>
111+
<p>Want these to be minified and inlined? The "Use token-shaker" option from setup does that.</p>
116112
<h3>Variables</h3>
117113
<p>These start with <code>--m3v-</code>, and let you send information to M3 Svelte.</p>
118114
<ul>

src/routes/docs/quick-start/+page.svelte

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import iconNext from "@ktibow/iconset-material-symbols/arrow-forward";
77
88
import Icon from "$lib/misc/Icon.svelte";
9-
import ConnectedButtons from "$lib/buttons/ConnectedButtons.svelte";
109
import Button from "$lib/buttons/Button.svelte";
1110
import { resolve } from "$app/paths";
1211
1312
import Snippet from "../Snippet.svelte";
1413
15-
let fontSelection = $state("gsans");
16-
let useKit: "yes" | "no" = $state("yes");
14+
let useTokenShaker = $state(false);
15+
let useVite = $state(false);
16+
let useCustomFont = $state(false);
1717
</script>
1818

1919
<svelte:head><title>Quick start</title></svelte:head>
@@ -25,48 +25,81 @@
2525
<Icon icon={iconDownload} />
2626
</div>
2727
<div class="text">Install M3 Svelte</div>
28+
<Button label>
29+
<input type="checkbox" bind:checked={useTokenShaker} />
30+
Use token-shaker?
31+
</Button>
2832
</h2>
29-
<Snippet
30-
name="install.sh"
31-
html={/* sh */ `pnpm install m3-svelte vite-plugin-functions-mixins -D`}
32-
/>
33+
{#if useTokenShaker}
34+
<Snippet
35+
name="install.sh"
36+
html={/* sh */ `pnpm install m3-svelte vite-plugin-functions-mixins vite-plugin-token-shaker -D`}
37+
/>
38+
{:else}
39+
<Snippet
40+
name="install.sh"
41+
html={/* sh */ `pnpm install m3-svelte vite-plugin-functions-mixins -D`}
42+
/>
43+
{/if}
3344
</li>
3445
<li>
3546
<h2>
3647
<div class="number">
3748
2
3849
<Icon icon={iconConfig} />
3950
</div>
40-
<div class="text">Enable functions and mixins</div>
41-
<ConnectedButtons>
42-
<Button variant="tonal" square label
43-
><input type="radio" value="yes" name="usekit" bind:group={useKit} />SvelteKit</Button
44-
>
45-
<Button variant="tonal" square label
46-
><input type="radio" value="no" name="usekit" bind:group={useKit} />Pure Vite</Button
47-
>
48-
</ConnectedButtons>
51+
<div class="text">Enable plugins</div>
52+
<Button label>
53+
<input type="checkbox" bind:checked={useVite} />
54+
Use pure Vite?
55+
</Button>
4956
</h2>
50-
{#if useKit == "yes"}
57+
{#if useVite}
58+
{#if useTokenShaker}
59+
<Snippet
60+
name="vite.config.ts"
61+
html={/* typescript */ `import { defineConfig } from "vite";
62+
import { svelte } from "@sveltejs/vite-plugin-svelte";
63+
import { functionsMixins } from "vite-plugin-functions-mixins";
64+
import { tokenShaker } from "vite-plugin-token-shaker";
65+
66+
export default defineConfig({
67+
plugins: [svelte(), functionsMixins({ deps: ["m3-svelte"] }), tokenShaker()],
68+
});`}
69+
/>
70+
{:else}
71+
<Snippet
72+
name="vite.config.ts"
73+
html={/* typescript */ `import { defineConfig } from "vite";
74+
import { svelte } from "@sveltejs/vite-plugin-svelte";
75+
import { functionsMixins } from "vite-plugin-functions-mixins";
76+
77+
export default defineConfig({
78+
plugins: [svelte(), functionsMixins({ deps: ["m3-svelte"] })],
79+
});`}
80+
/>
81+
{/if}
82+
{:else if useTokenShaker}
5183
<Snippet
5284
name="vite.config.ts"
5385
html={/* typescript */ `import { defineConfig } from "vite";
5486
import { sveltekit } from "@sveltejs/kit/vite";
5587
import { functionsMixins } from "vite-plugin-functions-mixins";
88+
import { tokenShaker } from "vite-plugin-token-shaker";
5689
5790
export default defineConfig({
58-
plugins: [sveltekit(), functionsMixins({ deps: ["m3-svelte"] })],
91+
plugins: [sveltekit(), functionsMixins({ deps: ["m3-svelte"] }), tokenShaker()],
5992
});`}
6093
/>
6194
{:else}
6295
<Snippet
6396
name="vite.config.ts"
6497
html={/* typescript */ `import { defineConfig } from "vite";
65-
import { svelte } from "@sveltejs/vite-plugin-svelte";
98+
import { sveltekit } from "@sveltejs/kit/vite";
6699
import { functionsMixins } from "vite-plugin-functions-mixins";
67100
68101
export default defineConfig({
69-
plugins: [svelte(), functionsMixins({ deps: ["m3-svelte"] })],
102+
plugins: [sveltekit(), functionsMixins({ deps: ["m3-svelte"] })],
70103
});`}
71104
/>
72105
{/if}
@@ -79,15 +112,15 @@ export default defineConfig({
79112
</div>
80113
<div class="text">Enable your <a href={resolve("/theme")}>theme snippet</a></div>
81114
</h2>
82-
{#if useKit == "yes"}
115+
{#if useVite}
116+
<Snippet name="index.ts" html={/* typescript */ `import "./app.css";`} />
117+
{:else}
83118
<Snippet
84119
name="+layout.svelte"
85120
html={/* svelte */ `<${""}script>
86-
import "../app.css";
121+
import "../app.css";
87122
</${""}script>`}
88123
/>
89-
{:else}
90-
<Snippet name="index.ts" html={/* typescript */ `import "./app.css";`} />
91124
{/if}
92125
<Snippet name="app.css" html={/* css */ `/* Your theme snippet */`} />
93126
</li>
@@ -97,29 +130,24 @@ export default defineConfig({
97130
4
98131
<Icon icon={iconType} />
99132
</div>
100-
<ConnectedButtons>
101-
<Button variant="tonal" square label>
102-
<input type="radio" value="gsans" name="font" bind:group={fontSelection} />Enable Google
103-
Sans
104-
</Button>
105-
<Button variant="tonal" square label>
106-
<input type="radio" value="manual" name="font" bind:group={fontSelection} />Enable a
107-
custom font
108-
</Button>
109-
</ConnectedButtons>
133+
<div class="text">Enable a font</div>
134+
<Button label>
135+
<input type="checkbox" bind:checked={useCustomFont} />
136+
Use custom font?
137+
</Button>
110138
</h2>
111-
{#if fontSelection == "gsans"}
112-
<Snippet
113-
name={useKit == "yes" ? "app.html" : "index.html"}
114-
html={/* html */ `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans+Flex:opsz,[email protected],400..700&display=swap" />`}
115-
/>
116-
{:else}
139+
{#if useCustomFont}
117140
<Snippet
118141
name="app.css"
119142
html={/* css */ `:root {
120143
--m3-font: [your font], system-ui;
121144
}`}
122145
/>
146+
{:else}
147+
<Snippet
148+
name={useVite ? "index.html" : "app.html"}
149+
html={/* html */ `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans+Flex:opsz,[email protected],400..700&display=swap" />`}
150+
/>
123151
{/if}
124152
</li>
125153
</ol>

0 commit comments

Comments
 (0)