- To set up a new Vue project, use either Vue CLI or Vite, with Vite being the recommended choice for most new projects due to its speed and modern tooling. 2. For Vue CLI, install it globally using npm install -g @vue/cli, create a project with vue create my-vue-app, select desired features like Vue 3, Router, and ESLint, then run the project with npm run serve, making it accessible at http://localhost:8080. 3. For Vite, create a project using npm create vite@latest my-vue-app -- --template vue, install dependencies with npm install, then start the dev server with npm run dev, typically available at http://localhost:5173. 4. Key differences include Vue CLI using Webpack for slower startup and more configuration options, while Vite uses native ES modules for faster startup and near-instant HMR, simpler configuration via vite.config.js, and is now the default in official Vue documentation. 5. Choose Vue CLI for structured learning or legacy integration, but use Vite for faster development and modern workflows, as it provides a smoother experience for new projects unless specific Vue CLI features are required.
Setting up a new Vue project is straightforward whether you use Vue CLI or Vite. Both tools are widely used, but they differ in speed, configuration, and modern features. Here’s how to get started with each.

Option 1: Using Vue CLI (Great for beginners and full Vue ecosystem)
Vue CLI is the official command-line tool for Vue.js. It provides a full-featured setup with built-in options for routing, state management, and testing.
Step 1: Install Vue CLI globally
Make sure you have Node.js (v16.0 or higher) installed, then run:

npm install -g @vue/cli
You can verify the installation with:
vue --version
Step 2: Create a new project
Run the following command and follow the prompts:

vue create my-vue-app
You’ll be asked to choose a preset:
- Default (Vue 3) or Default (Vue 2) – good for quick starts.
- Manually select features – lets you add Vue Router, Vuex, TypeScript, ESLint, etc.
For example, to use Vue 3 with Router and ESLint:
- Select:
Choose Vue version
,Babel
,Router
,Vuex
,CSS Pre-processors
,Linter / Formatter
- Choose Vue 3 when prompted.
Step 3: Run the project
Navigate into the project folder and start the dev server:
cd my-vue-app npm run serve
Your app will be available at http://localhost:8080
.
Option 2: Using Vite (Faster, modern, recommended for new projects)
Vite is a next-generation build tool that offers lightning-fast startup and HMR (Hot Module Replacement). It's now the recommended way to start new Vue projects.
Step 1: Create a Vite project with Vue
Run this command (no global installation needed):
npm create vite@latest my-vue-app -- --template vue
Or, for Vue with TypeScript:
npm create vite@latest my-vue-app -- --template vue-ts
This will create a new folder called my-vue-app
with a minimal Vue setup.
Step 2: Install dependencies
Go into the project directory and install dependencies:
cd my-vue-app npm install
Step 3: Start the development server
npm run dev
The server will start quickly, usually on http://localhost:5173
(port may vary).
Key Differences: Vue CLI vs Vite
Feature | Vue CLI | Vite |
---|---|---|
Build Tool | Webpack | Native ES modules Rollup |
Startup Speed | Slower (especially large apps) | Very fast |
HMR (Hot Reload) | Fast | Near-instant |
Configuration | vue.config.js | vite.config.js |
Learning Curve | Slightly higher | Simpler for basic setups |
Recommended for | Legacy or complex setups | New projects, modern workflows |
Which Should You Use?
- Use Vue CLI if you're learning Vue with a structured setup, need deep integration with legacy plugins, or want guided configuration.
- Use Vite if you want faster development, are starting a new project, or want to leverage modern tooling.
Vite is now the default choice in most Vue documentation and templates, including the official Vue tutorials.
Basically, both tools work well, but Vite gives you a smoother, faster experience out of the box. For most new projects, go with Vite unless you have specific needs that Vue CLI better supports.
The above is the detailed content of How to set up a new Vue project using Vue CLI or Vite. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

HeadlessUIinVue refers to a library of UI components that provide no preset styles and only contains core logic and behavior. Its features include: 1. No style restrictions, developers can customize the design; 2. Focus on barrier-free and interactive logic, such as keyboard navigation, state management, etc.; 3. Support Vue framework integration, exposing the control interface through combinable functions or components. Reasons for use include: maintaining design consistency, built-in accessibility, strong component reusability, and lightweight library size. In practical applications, developers need to write HTML and CSS themselves. For example, when building a drop-down menu, the library handles state and interaction, while developers decide on visual presentation. Mainstream libraries include HeadlessUI and RadixVue for TailwindLabs, suitable for

In Vue3, there are three ways to monitor nested properties using the watch function: 1. Use the getter function to accurately monitor specific nested paths, such as watch(()=>someObject.nested.property,callback); 2. Add the {deep:true} option to deeply monitor changes within the entire object, which is suitable for situations where the structure is complex and does not care about which property changes; 3. Return an array in the getter to listen to multiple nested values ??at the same time, which can be used in combination with deep:true; in addition, if ref is used, the nested properties in its .value need to be tracked through getter.

Vue3 has improved in many key aspects compared to Vue2. 1.Composition API provides a more flexible logical organization method, allowing centralized management of related logic, while still supporting Vue2's Options API; 2. Better performance and smaller package size, the core library is reduced by about 30%, the rendering speed is faster and supports better tree shake optimization; 3. The responsive system uses ES6Proxy to solve the problem of unable to automatically track attribute addition and deletion in Vue2, making the responsive mechanism more natural and consistent; 4. Built-in better support for TypeScript, support multiple node fragments and custom renderer API, improving flexibility and future adaptability. Overall, Vue3 is a smooth upgrade to Vue2,

Building a Vue component library requires designing the structure around the business scenario and following the complete process of development, testing and release. 1. The structural design should be classified according to functional modules, including basic components, layout components and business components; 2. Use SCSS or CSS variables to unify the theme and style; 3. Unify the naming specifications and introduce ESLint and Prettier to ensure the consistent code style; 4. Display the usage of components on the supporting document site; 5. Use Vite and other tools to package as NPM packages and configure rollupOptions; 6. Follow the semver specification to manage versions and changelogs when publishing.

It is recommended to use Vite to create Vue3 projects because it uses the browser's native ES module support and has a fast startup speed in development mode. 1. Make sure to install Node.js (16.x or higher) and npm/yarn/pnpm; 2. Run npmcreatevite@latestmy-vue-app--templatevue initialization project; 3. Follow the prompts to select TypeScript, VueRouter and other configurations; 4. Execute cdmy-vue-app and npminstall installation dependencies; 5. Use npmrundev to start the development server. Optional configurations include automatic browser opening, proxy settings, alias paths, and packaging optimizations. Recommended insurance

Defining routes in Vue projects requires understanding the structure and configuration. The steps are as follows: 1. Install and introduce vue-router, create a routing instance, and pass in a routes array containing path and component; 2. Use dynamic routing matching such as /user/:id to obtain parameters; 3. Use children attribute to implement nested routes; 4. Name the routes with the name attribute for jumping; 5. Use redirect for path redirect. After mastering these core points, you can configure routing efficiently.

? in regular expressions are used to convert greedy matches to non-greedy, achieving more accurate matches. 1. It makes the content as little as possible to match as little as possible to avoid mismatch across tags or fields; 2. It is often used in scenarios such as HTML parsing, log analysis, URL extraction, etc. that require precise control of the scope; 3. When using it, it is necessary to note that not all quantifiers are applicable. Some tools need to manually enable non-greedy mode, and complex structures need to be combined with grouping and assertions to ensure accuracy. Mastering this technique can significantly improve text processing efficiency.

CORSissuesinVueoccurduetothebrowser'ssame-originpolicywhenthefrontendandbackenddomainsdiffer.Duringdevelopment,configureaproxyinvue.config.jstoredirectAPIrequeststhroughthedevserver.Inproduction,ensurethebackendsetsproperCORSheaders,allowingspecifico
