You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 03-bundling/06-vite/06-typescript/README.md
+22-52Lines changed: 22 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
76
76
77
77
The rest is just a starting boilerplate configuration you can tweak based on your needs.
78
78
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:
80
80
81
81
_index.html_
82
82
@@ -145,6 +145,19 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
145
145
146
146
🔎 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.
147
147
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
+
148
161
- Time to start the project!
149
162
150
163
```bash
@@ -226,32 +239,18 @@ Install [Node.js and npm](https://nodejs.org/en/) (20.19.0 || >=22.12.0) if they
226
239
227
240
🔎 Check how we also get error feedback in the console.
228
241
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.
230
243
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'.
236
248
237
-
### Alternative 1
249
+
2 const numberB: string = 3;
250
+
~~~~~~~
238
251
239
-
- Let's update the `package.json` to run `tsc` before production build:
240
252
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
255
254
```
256
255
257
256
- 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
265
264
```
266
265
267
266
🔎 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:
"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.",
0 commit comments