We will set up the project using Vite, similar to how we did in the previous project.
Create a new Vite project using the following command:
Select the following options when prompted:
Navigate to the project directory and open it in Visual Studio Code:
The project structure is similar to the previous project, with the following files and directories:
Notice that the source code is already in the src
directory (unlike the Vanilla JavaScript template where we had to move the files). The style.css
file is also placed in the src
directory.
The src/vite-env.d.ts
file is a declaration file used in Vite projects to declare types for global variables or modules, particularly for Vite’s environment variables. Vite injects some special types and environment variables, and to get proper type checking and autocompletion for those in TypeScript, you need to have a declaration file like vite-env.d.ts
.
The scaffolded project also includes a tsconfig.json
file for TypeScript configuration. The TypeScript configuration is set up to target ESNext, use the bundler mode, and enable strict type checking.
The package.json
file includes dependencies for Vite and TypeScript. The build
script is configured to transpile TypeScript code to JavaScript using the tsc
command, followed by building the project with Vite.
Let’s simplify the project by removing the unnecessary files and code. Run the following commands:
Next, download the following favicon.png and add it to the public folder.
Finally, replace the content of the index.html
file with the following code:
We have set up a new Vite project for the Vanilla TypeScript Counter App. We could also install TailwindCSS and Prettier like we did in the previous projects, but we will skip that for now. We also skip adding .github/workflows/deploy.yml
to keep the project simple.