Sostieni AppuntiFacili con una piccola donazione su PayPal
Dona con PayPalVite (French for “fast”) is a modern frontend build tool. It provides two things most web projects need:
Manually configuring a compiler, a bundler, a dev server, and TypeScript support from scratch is a lot of tedious setup. Vite ships with sensible defaults for all of this out of the box, which is why it has become one of the most popular ways to start a new frontend (or general TypeScript) project.
TIP
Vite isn’t tied to one framework. It has official templates for vanilla TypeScript, React, Vue, Svelte, and more — the underlying dev server and build pipeline are the same either way.
Vite can generate a ready-to-use project structure from a template, so you don’t start from an empty folder:
npm init vite@latest vite_project -- --template vanilla-ts
Let’s break this command down:
npm init vite@latest fetches and runs the latest version of Vite’s project-creation tool (via create-vite) without installing anything globally.vite_project is the name of the folder that will be created for your new project.-- --template vanilla-ts passes extra arguments through npm init to the underlying tool: --template vanilla-ts tells it to use the vanilla TypeScript template — plain TypeScript with no UI framework attached, ideal for learning the language itself.INFO
The double dash -- is npm’s way of saying “everything after this belongs to the program being run, not to npm itself.” Without it, npm might try to interpret --template as its own flag.
Other common templates follow the same pattern, for example react-ts, vue-ts, or svelte-ts — swap vanilla-ts for any of these if you want a specific framework instead.
cd vite_project
Move into the freshly generated folder. Vite has already created a working project structure for you, roughly:
vite_project/
├── index.html
├── package.json
├── tsconfig.json
├── src/
│ ├── main.ts
│ └── style.css
└── public/
From here, the usual flow is:
npm install # install the project's dependencies (Vite itself, etc.)
npm run dev # start the development server
npm run dev starts Vite’s dev server (typically at http://localhost:5173) and watches your files: every time you save, the browser updates almost instantly.
When you’re ready to ship:
npm run build
This produces an optimized, minified bundle of plain JavaScript/HTML/CSS in a dist/ folder, ready to be deployed to any static hosting.
tsc setupCompare this to the manual workflow from the previous two lessons (npm init, install typescript, tsc --init, then tsc + node by hand):
tsc setup only compiles TypeScript to JavaScript — it does not bundle assets, serve HTML, or optimize a build for the browser.tsx) is often simpler and lighter. For anything that runs in a browser, Vite (or a similar bundler) is usually the better starting point.What is Vite primarily used for?
In `npm init vite@latest vite_project -- --template vanilla-ts`, what does `vanilla-ts` refer to?
What is the purpose of the `--` before `--template` in the init command?
Which command starts Vite's development server?
What does `npm run build` produce in a Vite project?
Why might you choose a manual tsc setup instead of Vite?
Scenario: You want to build a small interactive TypeScript demo that runs in the browser, with live reload while you develop it.
Task:
npm init vite@latest my-demo -- --template vanilla-ts.cd into the folder, run npm install, then npm run dev, and open the printed local URL in your browser.src/main.ts to change some text or add a console.log, save, and observe how quickly the browser updates.npm run build and inspect the generated dist/ folder’s contents.tsc/node workflow from the previous lesson — write down two concrete differences you noticed.Learning objective: understand what a bundler/dev-server tool like Vite adds on top of the raw TypeScript compiler, and get hands-on with scaffolding a real project from a template.
Prenota una lezione