Pre-order my new book on Vue Design Patterns at 30% discount. Click here for more details

How to Start a Vue App with Vue CLI

Published by Solomon Eseme's profile picture Solomon Eseme on  Sat, 06 May 2023 10:30:00 GMT

Vue.js is a popular JavaScript framework used for building user interfaces and single-page applications. Vue.js 3 is the latest version of Vue.js and comes with several new features and improvements that make it a great choice for building web applications.

In this tutorial, we will cover the steps needed to start a Vue.js 3 application from scratch. We will use the Vue CLI (Command Line Interface) to scaffold our project and configure it to use the latest version of Vue.js.

Prerequisites

Before starting, you need to have Node.js and npm installed on your machine. You can download and install the latest version of Node.js from the official website: https://nodejs.org/.

Once you have Node.js and npm installed, you can proceed to install the Vue CLI.

Installing Vue CLI

To install the Vue CLI, open your terminal and run the following command:

npm install -g @vue/cli

This command will install the Vue CLI globally on your machine. Once the installation is complete, you can check the version of the Vue CLI by running the following command:

vue --version

This command should output the version of the Vue CLI that you just installed.

Creating a New Vue.js Project

To create a new Vue.js project, navigate to the directory where you want to create the project and run the following command:

vue create my-project

Replace my-project with the name of your project. This command will create a new Vue.js project in a directory called my-project. The Vue CLI will ask you to pick a preset for your project. You can either choose the default preset or manually select features.

Once you have selected your preset, the Vue CLI will install the necessary dependencies and scaffold your project. This process may take a few minutes depending on your internet speed and the size of your project.

Project Structure

Let's take a quick look at the project structure that was created for us:

my-app/
|- node_modules/
|- public/
| |- favicon.ico
| |- index.html
|- src/
| |- assets/
| |- components/
| |- App.vue
| |- main.js
|- .gitignore
|- babel.config.js
|- package-lock.json
|- package.json
|- README.md

Here's a brief explanation of what each file and folder does:

  • node_modules/: Contains all the dependencies for the project.
  • public/: Contains the index.html file, which is the entry point for the app.
  • src/: Contains all the source code for the app.
  • assets/: Contains static assets like images and fonts.
  • components/: Contains reusable Vue.js components.
  • App.vue: The main Vue.js component.
  • main.js: The entry point for the app.
  • .gitignore: Specifies files and folders that should be ignored by Git.
  • babel.config.js: Configures Babel for the project.
  • package-lock.json: A file generated by npm that lists the exact versions of all the dependencies.
  • package.json: Contains metadata about the project, as well as the project's dependencies and scripts.
  • README.md: The readme file for the project.

Running the Development Server

Once the project has been created, navigate to the project directory by running the following command:

cd my-project

Replace my-project with the name of your project. Once you are in the project directory, run the following command to start the development server:

npm run serve

This command will start the development server and open your web browser to http://localhost:8080, where you can see your Vue.js application running.

Conclusion

In this tutorial, we covered the steps needed to start a new Vue.js 3 project from scratch. We used the Vue CLI to scaffold our project and configured it to use the latest version of Vue.js. We also showed how to run the development server and view the application in the web browser.

Vue.js is a powerful framework that can be used to build enterprise-level web applications. By following this tutorial, you should now have a solid foundation to start building your own Vue.js applications. Happy coding!

Architecting Vue.js 3 Enterprise-Ready Web Applications

Get the FREE chapter!

With this 15+ pages long chapter You will learn how to unit test a Vue.js 3 component and the components and pages’ methods: You will also learn Unit Testing tools such as Jest and Mocha and use them to effectively unit Test an enterprise project.

    Architecting Vue.js 3 Enterprise-Ready Web Applications chapter 9 Best Practice in Unit Testing