Step 2
Let's explore the template project created by vite:
.
└── brick-breaker
├── counter.js
├── index.html
├── javascript.svg
├── main.js
├── package.json
├── public
│ └── vite.svg
└── style.css
- The
.gitignoreis a minimal list of files and folders to be ignored when Git tracks this project. - The
javascript.svgandvite.svgare Scalar Vector Graphics (SVG). These graphics are displayed in the sample web app that comes in the template project. - The
index.htmlis a minimal boilerplate HTML file similar to those we created in the earlier chapters. - The
main.jsis a minimal JavaScript file linked to theindex.htmlsimilar to those we created in the earlier chapters. It makes use ofcounter.jswhich implements a simple counter! - The
style.cssis linked to theindex.htmlfile and provides minimal styling similar to those we created in the earlier chapters. - The
package.jsonholds metadata relevant to the project. It is also used by Yarn for managing the project's dependencies, scripts, version, and a lot more. We will explore this further in a future chapter.
Let's glance over the content of package.json:
{
"name": "brick-breaker",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^3.1.0"
}
}
Notice the section under "scripts." We can use the keywords under the script to run the commands associated with them. First, however, you must install the "dependencies" for this project. In this case, the only dependency is the vite library.
Open the terminal and change the directory to brick-breaker folder. Then, run the following command.
yarn install
It will take a moment for the dependencies to be installed. Once done, you will have a folder, node_modules, added to brick-breaker. This folder contains the dependencies of your application (and their dependencies).
Make sure to always exclude the
node_modulesfolder from your Git repository. The folder name is already included in your.gitignorefile.
Additionally, a file, yarn.lock, is added to the brick-breaker folder. This file contains the dependency tree of your application (its dependencies, and the dependencies of the dependencies, etc.).
The
yarn.lockis automatically generated and modified. Therefore, you should never directly edit it.
Make sure to include yarn.lock in your Git repository. You need this file to get the exact dependencies your project is built on for any subsequent installs.