Skip to content

Commit ca66163

Browse files
committed
chore: update 06-typescript example, cascade other examples
1 parent 623c8c8 commit ca66163

8 files changed

Lines changed: 15 additions & 90 deletions

File tree

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

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -226,32 +226,18 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
226226

227227
🔎 Check how we also get error feedback in the console.
228228

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

231-
```bash
232-
npm run preview
233-
```
234-
235-
- But there are a couple of alternatives we can do:
236-
237-
### Alternative 1
238-
239-
- Let's update the `package.json` to run `tsc` before production build:
231+
```text
232+
vite v7.0.4 building for production...
233+
✓ 2 modules transformed.
234+
src/index.ts:2:7 - error TS2322: Type 'number' is not assignable to type 'string'.
240235
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-
```
236+
2 const numberB: string = 3;
237+
~~~~~~~
250238
251-
🔎 Let's check we cannot build for production until all compilation errors are cleared:
252239
253-
```bash
254-
npm run build
240+
Found 1 error in src/index.ts:2
255241
```
256242

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

267253
🔎 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.

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
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",
1612
"sass-embedded": "^1.89.2",
1713
"tslib": "^2.8.1",
1814
"typescript": "^5.8.3",
19-
"vite": "^7.0.2",
20-
"vite-plugin-checker": "^0.9.3"
15+
"vite": "^7.0.4",
16+
"vite-plugin-checker": "^0.10.0"
2117
},
2218
"dependencies": {
2319
"bootstrap": "^5.3.7"
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { defineConfig } from "vite";
22
import checker from "vite-plugin-checker";
3-
import typescript from "@rollup/plugin-typescript";
43

54
export default defineConfig({
65
plugins: [checker({ typescript: true })],
7-
build: {
8-
rollupOptions: {
9-
plugins: [typescript({ noEmitOnError: false })],
10-
},
11-
},
126
});

03-bundling/06-vite/07-react/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,11 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
6060
```diff
6161
import { defineConfig } from "vite";
6262
import checker from "vite-plugin-checker";
63-
import typescript from "@rollup/plugin-typescript";
6463
+ import react from "@vitejs/plugin-react";
6564

6665
export default defineConfig({
6766
- plugins: [checker({ typescript: true })],
6867
+ plugins: [checker({ typescript: true }), react()],
69-
build: {
70-
rollupOptions: {
71-
plugins: [typescript()],
72-
},
73-
},
7468
});
7569
```
7670

@@ -140,7 +134,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
140134
npm start
141135
```
142136

143-
🔎 First of all, chech your `react` application is up and running!
137+
🔎 First of all, check your `react` application is up and running!
144138

145139
🔎 Then, look at the dev-tools `network` tab (refresh if needed) and, apart from the source code ES modules we already know, you will see a couple of `vite` pre-bundled dependencies: `react-dom_client` and `react_jsx-dev-runtime`. Take a look at both requests, they share a few things in common:
146140

03-bundling/06-vite/07-react/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
"preview": "vite preview"
1111
},
1212
"devDependencies": {
13-
"@rollup/plugin-typescript": "^12.1.4",
1413
"@types/react": "^19.1.8",
1514
"@types/react-dom": "^19.1.6",
1615
"@vitejs/plugin-react": "^4.6.0",
1716
"sass-embedded": "^1.89.2",
18-
"tslib": "^2.8.1",
1917
"typescript": "^5.8.3",
20-
"vite": "^7.0.2",
21-
"vite-plugin-checker": "^0.9.3"
18+
"vite": "^7.0.4",
19+
"vite-plugin-checker": "^0.10.0"
2220
},
2321
"dependencies": {
2422
"bootstrap": "^5.3.7",
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { defineConfig } from "vite";
22
import checker from "vite-plugin-checker";
3-
import typescript from "@rollup/plugin-typescript";
43
import react from "@vitejs/plugin-react";
54

65
export default defineConfig({
76
plugins: [checker({ typescript: true }), react()],
8-
build: {
9-
rollupOptions: {
10-
plugins: [typescript()],
11-
},
12-
},
137
});

03-bundling/06-vite/08-env-vars/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
"preview": "vite preview"
1111
},
1212
"devDependencies": {
13-
"@rollup/plugin-typescript": "^12.1.4",
1413
"@types/react": "^19.1.8",
1514
"@types/react-dom": "^19.1.6",
1615
"@vitejs/plugin-react": "^4.6.0",
1716
"sass-embedded": "^1.89.2",
18-
"tslib": "^2.8.1",
1917
"typescript": "^5.8.3",
20-
"vite": "^7.0.2",
21-
"vite-plugin-checker": "^0.9.3"
18+
"vite": "^7.0.4",
19+
"vite-plugin-checker": "^0.10.0"
2220
},
2321
"dependencies": {
2422
"bootstrap": "^5.3.7",
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { defineConfig } from "vite";
22
import checker from "vite-plugin-checker";
3-
import typescript from "@rollup/plugin-typescript";
43
import react from "@vitejs/plugin-react";
54

65
export default defineConfig({
76
plugins: [checker({ typescript: true }), react()],
8-
build: {
9-
rollupOptions: {
10-
plugins: [typescript()],
11-
},
12-
},
137
});

0 commit comments

Comments
 (0)