Skip to content

Commit bd5c395

Browse files
committed
feat: add autoprefixer and cssnano for improved CSS handling
refactor: update Counter component to accept className prop for styling delete: remove unused Input component refactor: replace Input component with new TextInput component in the main page chore: update Vite configuration to include PostCSS plugins for CSS optimization feat: create TextInput component for reactive text input with output display
1 parent 93e80ae commit bd5c395

File tree

7 files changed

+214
-51
lines changed

7 files changed

+214
-51
lines changed

bun.lock

Lines changed: 131 additions & 3 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"@sveltejs/adapter-static": "^3.0.8",
2020
"@sveltejs/kit": "^2.21.0",
2121
"@sveltejs/vite-plugin-svelte": "^5.0.3",
22+
"autoprefixer": "^10.4.21",
23+
"cssnano": "^7.0.7",
2224
"eslint": "^9.27.0",
2325
"eslint-config-prettier": "^10.1.5",
2426
"eslint-plugin-svelte": "^3.8.1",

src/lib/components/Counter.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
let count = $state(0);
44
const times = $derived(count == 1 ? 'time' : 'times');
55
6-
const { btnStyle = 'primary' } = $props();
6+
const {
7+
btnStyle = 'primary',
8+
className = ''
9+
} = $props();
710
</script>
811

912
<!-- onclick event handler is set to the increment function -->
1013
<!-- Button text displays the current count and the word "time" with appropriate pluralization -->
11-
<button type="button" class="btn btn-{btnStyle} w-100" onclick={() => count++}>
14+
<button type="button" class="btn btn-{btnStyle} w-100 {className}" onclick={() => count++}>
1215
Pressed {count}
1316
{times}
1417
</button>

src/lib/components/Input.svelte

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

src/lib/components/TextInput.svelte

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script>
2+
let {
3+
placeholder = 'Enter your text here...',
4+
} = $props();
5+
let inputText = $state('');
6+
</script>
7+
8+
9+
<div class="mb-3">
10+
<label for="exampleFormControlTextarea1" class="form-label">Insert Reactive Text Here:</label>
11+
<textarea
12+
bind:value={inputText}
13+
class="form-control"
14+
id="exampleFormControlTextarea1"
15+
{placeholder}
16+
rows="3"
17+
></textarea>
18+
</div>
19+
<div class="inputTextOutput bg-light text-bg-light rounded-3 border-1 border-black">
20+
{inputText}
21+
</div>
22+
23+
<style lang="scss">
24+
.inputTextOutput {
25+
font-size: 1.5rem;
26+
min-height: 3rem;
27+
padding: 0.5rem 1rem;
28+
}
29+
</style>

src/routes/+page.svelte

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Counter from '$lib/components/Counter.svelte';
33
import Logos from '$lib/components/Logos.svelte';
44
import Modal from '$lib/components/Modal.svelte';
5-
import Input from '$lib/components/Input.svelte';
5+
import TextInput from '$lib/components/TextInput.svelte';
66
import { onMount } from 'svelte';
77
88
let hrefLocation = '';
@@ -28,28 +28,34 @@
2828
<Logos />
2929
</div>
3030

31-
<div class="mb-5 col-xl-4 col-md-6">
32-
<div class="mb-3 d-flex justify-content-between gap-3">
33-
<Counter btnStyle="secondary" />
34-
<Modal
35-
id="modal-demo"
36-
btnTitle="Modal Demo"
37-
modalTitle="Cat's Diary"
38-
body="Make muffins give attitude chase mice sweet beast under the bed all of a sudden go crazy behind the couch destroy couch intently stare at the same spot chew ipad power cord bag stretch claw drapes, leave dead animals as gifts attack feet flop over hopped up on goofballs hunt anything that moves hide when guests come over intrigued by the shower stand in front of the computer screen rub face on everything."
39-
/>
31+
<div class="container">
32+
<div class="row g-3 col-12 col-md-6">
33+
<div class="col-6">
34+
<Counter btnStyle="secondary" />
35+
</div>
36+
<div class="col-6">
37+
<Modal
38+
class="col-6"
39+
id="modal-demo"
40+
btnTitle="Modal Demo"
41+
modalTitle="Cat's Diary"
42+
body="Make muffins give attitude chase mice sweet beast under the bed all of a sudden go crazy behind the couch destroy couch intently stare at the same spot chew ipad power cord bag stretch claw drapes, leave dead animals as gifts attack feet flop over hopped up on goofballs hunt anything that moves hide when guests come over intrigued by the shower stand in front of the computer screen rub face on everything."
43+
/>
44+
</div>
45+
<div class="col-12">
46+
<a
47+
href="https://pagespeed.web.dev/report?url={hrefLocation}"
48+
target="_blank"
49+
class="btn btn-light w-100"
50+
rel="noreferrer"
51+
>
52+
Google PageSpeed Report
53+
</a>
54+
</div>
55+
<div class="col-12">
56+
<TextInput />
57+
</div>
4058
</div>
41-
42-
<div class="mb-3">
43-
<a
44-
href="https://pagespeed.web.dev/report?url={hrefLocation}"
45-
target="_blank"
46-
class="btn btn-light w-100"
47-
rel="noreferrer"
48-
>
49-
Google PageSpeed Report
50-
</a>
51-
</div>
52-
<Input />
5359
</div>
5460

5561

vite.config.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { sveltekit } from '@sveltejs/kit/vite';
1+
const IN_PRODUCTION = process.env.NODE_ENV === 'production';
22
import { defineConfig } from 'vite';
3+
import { sveltekit } from '@sveltejs/kit/vite';
34
import webfontDownload from 'vite-plugin-webfont-dl';
4-
const IN_PRODUCTION = process.env.NODE_ENV === 'production';
5-
import htmlPurge from 'vite-plugin-purgecss';
5+
// import { purgeCSSPlugin } from '@fullhuman/postcss-purgecss';
6+
import htmlPurge from 'vite-plugin-purgecss'
7+
import autoprefixer from 'autoprefixer';
8+
import cssnano from 'cssnano';
69
const bootstrap = 'node_modules/bootstrap';
710

811
export default defineConfig({
@@ -38,17 +41,26 @@ export default defineConfig({
3841
}),
3942

4043
/* ## Download Google Fonts and attach them with production build for offline use */
41-
IN_PRODUCTION &&
42-
webfontDownload([
43-
'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'
44-
])
44+
IN_PRODUCTION && webfontDownload([
45+
'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'
46+
])
4547
],
4648

4749
css: {
4850
preprocessorOptions: {
4951
scss: {
5052
api: 'modern'
5153
}
54+
},
55+
postcss: {
56+
plugins: [
57+
// --- CSSNano is a modern CSS minifier based on the PostCSS ecosystem.
58+
cssnano({
59+
preset: ["default", { discardComments: { removeAll: true } }],
60+
}),
61+
// --- Autoprefixer is used to add vendor prefixes to CSS rules using values from "Can I Use".
62+
autoprefixer
63+
]
5264
}
5365
},
5466

0 commit comments

Comments
 (0)