Skip to content

Commit cc64bc7

Browse files
authored
Merge pull request #819 from Lemoncode/chore/vite-update
Update vite examples
2 parents a1f1818 + 32b4296 commit cc64bc7

47 files changed

Lines changed: 618 additions & 137 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/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": "^7.0.2"
12+
"vite": "^7.0.4"
1313
}
1414
}

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": "^7.0.2"
12+
"vite": "^7.0.4"
1313
}
1414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"devDependencies": {
1212
"sass-embedded": "^1.89.2",
13-
"vite": "^7.0.2"
13+
"vite": "^7.0.4"
1414
}
1515
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
},
1111
"devDependencies": {
1212
"sass-embedded": "^1.89.2",
13-
"vite": "^7.0.2"
13+
"vite": "^7.0.4"
1414
},
1515
"dependencies": {
16-
"bootstrap": "^5.3.3"
16+
"bootstrap": "^5.3.7"
1717
}
1818
}

03-bundling/06-vite/05-images/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
},
1111
"devDependencies": {
1212
"sass-embedded": "^1.89.2",
13-
"vite": "^7.0.2"
13+
"vite": "^7.0.4"
1414
},
1515
"dependencies": {
16-
"bootstrap": "^5.3.3"
16+
"bootstrap": "^5.3.7"
1717
}
1818
}

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

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
7676

7777
The rest is just a starting boilerplate configuration you can tweak based on your needs.
7878

79-
- Let's simplify our `index.html` file just to focus on TS:
79+
- ⚠️ It's time to do a bit of cleanup. Let's simplify our `index.html` file just to focus on TS:
8080

8181
_index.html_
8282

@@ -145,6 +145,19 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
145145

146146
🔎 Notice we didn't need to add module syntax like `export {}` because TS already understands it's a module since we added `"type": "module"` in `package.json` file.
147147

148+
- ⚠️ Finally, now that we removed the usage of `SASS`, `bootstrap` and `images` let's delete related files to keep project tidy:
149+
150+
```bash
151+
DELETE src/content/
152+
DELETE src/mystyles.scss
153+
```
154+
155+
and also uninstall dependencies:
156+
157+
```bash
158+
npm uninstall bootstrap sass-embedded
159+
```
160+
148161
- Time to start the project!
149162

150163
```bash
@@ -226,32 +239,18 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
226239

227240
🔎 Check how we also get error feedback in the console.
228241

229-
- Unfortunately, it doesn't prevent us from generating the production bundle, eventhough the `build` script apparently failed. Actually you can run it with:
242+
- We can see thank to `vite-plugin-checker` it is preventing us from generating the production bundle, with errors.
230243

231-
```bash
232-
npm run preview
233-
```
234-
235-
- But there are a couple of alternatives we can do:
244+
```text
245+
vite v7.0.4 building for production...
246+
✓ 2 modules transformed.
247+
src/index.ts:2:7 - error TS2322: Type 'number' is not assignable to type 'string'.
236248
237-
### Alternative 1
249+
2 const numberB: string = 3;
250+
~~~~~~~
238251
239-
- Let's update the `package.json` to run `tsc` before production build:
240252
241-
```diff
242-
"scripts": {
243-
"start": "vite",
244-
+ "type-check": "tsc --noEmit",
245-
+ "prebuild": "npm run type-check",
246-
"build": "vite build",
247-
"preview": "vite preview"
248-
},
249-
```
250-
251-
🔎 Let's check we cannot build for production until all compilation errors are cleared:
252-
253-
```bash
254-
npm run build
253+
Found 1 error in src/index.ts:2
255254
```
256255

257256
- So, we can only fix the issue to continue:
@@ -265,32 +264,3 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
265264
```
266265

267266
🔎 Run now a production build and check how it goes smoothly.
268-
269-
### Alternative 2
270-
271-
- Let's tweak `rollup`, which is run under the hood for bundling in production, and let's configure its typescript plugin to prevent emitting any artifact if transpilation fails. First, install the plugin and a required `tslib` dependency:
272-
273-
```bash
274-
npm install @rollup/plugin-typescript tslib --save-dev
275-
```
276-
277-
- Then, add the following to `vite` config file:
278-
279-
_vite.config.ts_
280-
281-
```diff
282-
import { defineConfig } from "vite";
283-
import checker from "vite-plugin-checker";
284-
+ import typescript from "@rollup/plugin-typescript";
285-
286-
export default defineConfig({
287-
plugins: [checker({ typescript: true })],
288-
+ build: {
289-
+ rollupOptions: {
290-
+ plugins: [typescript()],
291-
+ },
292-
+ },
293-
});
294-
```
295-
296-
> By default it takes our `tsconfig.json` as reference.
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
{
22
"name": "hello-vite",
33
"private": true,
4-
"type": "module",
54
"version": "0.0.0",
65
"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.",
76
"scripts": {
87
"start": "vite --host",
9-
"type-check": "tsc --noEmit",
10-
"prebuild": "npm run type-check",
118
"build": "vite build",
129
"preview": "vite preview"
1310
},
1411
"devDependencies": {
15-
"@rollup/plugin-typescript": "^12.1.4",
16-
"sass-embedded": "^1.89.2",
1712
"tslib": "^2.8.1",
1813
"typescript": "^5.8.3",
19-
"vite": "^7.0.2",
20-
"vite-plugin-checker": "^0.9.3"
21-
},
22-
"dependencies": {
23-
"bootstrap": "^5.3.3"
14+
"vite": "^7.0.4",
15+
"vite-plugin-checker": "^0.10.0"
2416
}
2517
}
-21.9 KB
Binary file not shown.
-14.2 KB
Binary file not shown.

03-bundling/06-vite/06-typescript/src/mystyles.scss

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

0 commit comments

Comments
 (0)