Skip to content

Commit f10e7aa

Browse files
authored
Merge pull request #794 from Lemoncode/chore/update-vite-demos
[chore] Update Vite demos to v6
2 parents dada2a9 + 6a9eeae commit f10e7aa

65 files changed

Lines changed: 343 additions & 7874 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

03-bundling/06-vite/01-basic/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (18 / 20+) if they are not alr
6464

6565
```diff
6666
"scripts": {
67-
+ "build": "vite build",
67+
+ "build": "vite build"
6868
- "test": "echo \"Error: no test specified\" && exit 1"
6969
},
7070
```
@@ -80,11 +80,11 @@ Install [Node.js and npm](https://nodejs.org/en/) (18 / 20+) if they are not alr
8080
```text
8181
dist
8282
├── assets
83-
│ └── index.<hash>.js
83+
│ └── index-<hash>.js
8484
└── index.html
8585
```
8686

87-
If we inspect `assets/index.<hash>.js` we can notice the file is production ready because:
87+
If we inspect `assets/index-<hash>.js` we can notice the file is production ready because:
8888

8989
- It's already hashed (cache-busting strategy to bypass the browser cache completely).
9090
- File is minified.
@@ -189,10 +189,10 @@ Install [Node.js and npm](https://nodejs.org/en/) (18 / 20+) if they are not alr
189189

190190
```diff
191191
- console.log("This app is using Vite");
192-
+ console.log("New code update, it will to defeat cache !!!");
192+
+ console.log("New code update, it will bypass the cache!");
193193
```
194194

195-
- Check again the last request for `index.js`, now the URL changed, cache busting has been applied and a new hash in the form of a query param has been added to the URL with the purpose of defeating browser cache and force a download of this modified module. This hash is just a timestamp in `ms` with the date and time of the change (compilation timestamp).You can convert it back to `Date` to check it out by doing:
195+
- Check again the last request for `index.js`, now the URL changed, cache busting has been applied and a new hash in the form of a query param has been added to the URL with the purpose of bypassing browser cache and force a download of this modified module. This hash is just a timestamp in `ms` with the date and time of the change (compilation timestamp).You can convert it back to `Date` to check it out by doing:
196196

197197
```js
198198
console.log(new Date(t));

03-bundling/06-vite/01-basic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"version": "0.0.0",
55
"description": "Let's start with a very basic sample, just add an html plus a simple console log (E5). This is what you can find in the getting started tutorial.",
66
"scripts": {
7-
"start": "vite",
7+
"start": "vite --host",
88
"build": "vite build",
99
"preview": "vite preview"
1010
},
1111
"devDependencies": {
12-
"vite": "^5.3.3"
12+
"vite": "^6.0.3"
1313
}
1414
}

03-bundling/06-vite/02-custom-css/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (18 / 20+) if they are not alr
7575
🔍 Open file `dist/index.html` and notice how there is a new `<link>` tag created for us to reference the CSS file:
7676

7777
```html
78-
<link rel="stylesheet" href="/assets/index.29b4e7b8.css" />
78+
<link rel="stylesheet" href="/assets/index-29b4e7b8.css" />
7979
```
8080

81-
🔍 Also notice our CSS file has been renamed to `index.<hash>.css` and its content has been minified.
81+
🔍 Also notice our CSS file has been renamed to `index-<hash>.css` and its content has been minified.

03-bundling/06-vite/02-custom-css/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"preview": "vite preview"
1010
},
1111
"devDependencies": {
12-
"vite": "^5.3.3"
12+
"vite": "^6.0.3"
1313
}
1414
}

03-bundling/06-vite/03-sass/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ Install [Node.js and npm](https://nodejs.org/en/) (18 / 20+) if they are not alr
5656
💥 Notice we got an error here:
5757

5858
```cmd
59-
[vite] Internal server error: Preprocessor dependency "sass" not found. Did you install it?
59+
[vite] Internal server error: Preprocessor dependency "sass-embedded" not found. Did you install it? Try `npm install -D sass-embedded`.
6060
Plugin: vite:css
6161
```
6262

63-
👍🏼 In fact is a `vite` reminder to install `sass` preprocessor dependency. We forgot to do it!
63+
👍🏼 In fact is a `vite` reminder to install `sass-embedded` preprocessor dependency. We forgot to do it!
6464

65-
- Let's go then! Just add `sass` to our project as development dependency. First, stop the server and then run:
65+
> Note `sass-embedded` has same API that `sass` package but it's faster.
66+
67+
- Let's go then! Just add `sass-embedded` to our project as development dependency. First, stop the server and then run:
6668

6769
```bash
68-
npm install sass --save-dev
70+
npm install sass-embedded --save-dev
6971
```
7072

7173
- Now run the dev server again:
@@ -82,12 +84,10 @@ Install [Node.js and npm](https://nodejs.org/en/) (18 / 20+) if they are not alr
8284
npm run build
8385
```
8486

85-
🔍 Notice in `dist/assets/index.<hash>.css` the file has been transpiled correctly.
87+
🔍 Notice in `dist/assets/index-<hash>.css` the file has been transpiled correctly.
8688

8789
```css
88-
.red-background {
89-
background-color: teal;
90-
}
90+
.red-background{background-color:teal}
9191
```
9292

9393
👍🏼 `vite` supports `sass` with not as much hassle.

03-bundling/06-vite/03-sass/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"version": "0.0.0",
55
"description": "Let's start with a very basic sample, just add an html plus a simple console log (E5). This is what you can find in the getting started tutorial.",
66
"scripts": {
7-
"start": "vite",
7+
"start": "vite --host",
88
"build": "vite build",
99
"preview": "vite preview"
1010
},
1111
"devDependencies": {
12-
"sass": "^1.77.6",
13-
"vite": "^5.3.3"
12+
"sass-embedded": "^1.83.0",
13+
"vite": "^6.0.3"
1414
}
1515
}

03-bundling/06-vite/04-bootstrap/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ Install [Node.js and npm](https://nodejs.org/en/) (14.18+ / 16+) if they are not
4343

4444
```diff
4545
...
46+
- <body>
4647
+ <body class="m-3">
4748
<h1>Check the console log</h1>
4849
+ <div class="card" style="width: 18rem">
4950
+ <div class="card-body">
5051
+ <h5 class="card-title">Card title</h5>
51-
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
52+
+ <p class="card-text">
53+
+ Some quick example text to build on the card title and make up the bulk of the card's content.
54+
+ </p>
5255
+ <a href="#" class="btn btn-primary">Go somewhere</a>
5356
+ </div>
5457
+ </div>
@@ -65,7 +68,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (14.18+ / 16+) if they are not
6568

6669
🔎 Verify `bootstrap` styles work properly and you see the new component.
6770

68-
> Important: we have not added a depencency (in vite context) yet, even if the css is comming from `node_modules` and it won't change frequently. CSS files are not pre-bundled but treated as source modules, unless we adjust under-the-hood `esbuild` options and add a plugin for bundling css. See [this issue](https://github.com/vitejs/vite/issues/7719).
71+
> Important: we have not added a dependency (in vite context) yet, even if the css is coming from `node_modules` and it won't change frequently. CSS files are not pre-bundled but treated as source modules, unless we adjust under-the-hood `esbuild` options and add a plugin for bundling css. See [this issue](https://github.com/vitejs/vite/issues/7719).
6972
7073
- ⚙ As an alternative, we could also import bootstrap from `index.html`. Let's first remove the `import` clause from `index.js`:
7174

@@ -99,4 +102,4 @@ Install [Node.js and npm](https://nodejs.org/en/) (14.18+ / 16+) if they are not
99102
npm run build
100103
```
101104

102-
Notice in `dist/assets/index.<hash>.css` Bootstrap's CSS is included.
105+
Notice in `dist/assets/index-<hash>.css` Bootstrap's CSS is included.

03-bundling/06-vite/04-bootstrap/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ <h1>Check the console log</h1>
1313
<div class="card-body">
1414
<h5 class="card-title">Card title</h5>
1515
<p class="card-text">
16-
Some quick example text to build on the card title and make up the
17-
bulk of the card's content.
16+
Some quick example text to build on the card title and make up the bulk of the card's content.
1817
</p>
1918
<a href="#" class="btn btn-primary">Go somewhere</a>
2019
</div>

03-bundling/06-vite/04-bootstrap/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"version": "0.0.0",
55
"description": "Let's start with a very basic sample, just add an html plus a simple console log (E5). This is what you can find in the getting started tutorial.",
66
"scripts": {
7-
"start": "vite",
7+
"start": "vite --host",
88
"build": "vite build",
99
"preview": "vite preview"
1010
},
1111
"devDependencies": {
12-
"sass": "^1.69.5",
13-
"vite": "^4.5.0"
12+
"sass-embedded": "^1.83.0",
13+
"vite": "^6.0.3"
1414
},
1515
"dependencies": {
16-
"bootstrap": "^5.3.2"
16+
"bootstrap": "^5.3.3"
1717
}
1818
}

03-bundling/06-vite/05-images/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ Install [Node.js and npm](https://nodejs.org/en/) (14.18+ / 16+) if they are not
113113
```bash
114114
dist
115115
├── assets
116-
│ ├── index.269d697a.css
117-
│ ├── index.78986298.js
118-
│ ├── logo_1.6bb1b83d.png
119-
│ └── logo_2.cce7736d.png
116+
│ ├── index-269d697a.css
117+
│ ├── index-78986298.js
118+
│ ├── logo_1-6bb1b83d.png
119+
│ └── logo_2-cce7736d.png
120120
└── index.html
121121
```
122122

123123
🔎 Also notice in `dist/index.html` how `logo_2.png` source path has been added with its corresponding hash:
124124

125125
```html
126-
<img src="/assets/logo_2.cce7736d.png" alt="logo lemoncode" />
126+
<img src="/assets/logo_2-cce7736d.png" alt="logo lemoncode" />
127127
```

0 commit comments

Comments
 (0)