Welcome to our comprehensive guide on Vite JS, a modern, fast, and lean front-end build tool for building modern web applications. We'll walk you through creating a Vanilla JavaScript template using Vite, perfect for beginners and intermediate learners.
First, let's install Node.js, as Vite requires it.
node -v # Check if Node.js is installed
npm -v # Check if npm is installed (comes with Node.js)If not installed, follow the official Node.js installation guide.
Once Node.js is installed, we can install Vite.
npm install -g vite-g flag installs the package globally, so you can use it from any directory.Let's create a new Vite project.
vite create my-vanilla-app
cd my-vanilla-appmy-vanilla-app is the name of our project. You can name it anything you like.cd command navigates us into our project directory.Now, let's start our development server.
viteYour browser should automatically open http://localhost:5000/.
Since we're focusing on Vanilla JavaScript, let's remove TypeScript from our project.
rm src/main.ts
touch src/main.js.ts) file with JavaScript (.js).main.js, for our Vanilla JavaScript code.Now, let's add some simple JavaScript code to src/main.js.
// src/main.js
document.body.style.backgroundColor = 'lightblue';
console.log('Hello, Vanilla JavaScript!');Save the file, and you should see the background of the page change to light blue.
main.js file to make your project interactive.What does `vite` command do?
How do we navigate into our project directory after creation?
How do we run our Vite project?