Vue Academy · Lesson

CLI Configuration and Plugins

Configure the CLI and add plugins to extend your project.

Lesson 3 of 313 steps

CLI Configuration and Plugins is a free Vue Academy lesson on CoddyKit. This is lesson 3 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 3 lessons in total.

Configuring Your Build

Both Vue CLI and Vite let you customize the build through a config file.

  • Vue CLI uses vue.config.js
  • Vite uses vite.config.js

Here you add plugins, set aliases, configure the dev server, and more.

vite.config.js Basics

A typical vite.config.js imports the Vue plugin and exports a config object.

import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"

export default defineConfig({
  plugins: [vue()],
  server: {
    port: 3000
  }
})

vue.config.js Basics

For Vue CLI projects, vue.config.js exports configuration the same way.

const { defineConfig } = require("@vue/cli-service")

module.exports = defineConfig({
  devServer: {
    port: 8080
  }
})

Adding Plugins

Plugins extend the build with new capabilities.

  • Install with npm
  • Import in the config file
  • Add to the plugins array
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"

export default defineConfig({
  plugins: [vue(), vueJsx()]
})

Environment Variables

Store configuration that changes between environments in .env files.

  • .env loaded everywhere
  • .env.development for dev only
  • .env.production for production builds

Defining Env Variables

In Vite, variables must be prefixed with VITE_ to be exposed to your client code.

# .env file
VITE_API_URL=https://api.example.com
VITE_APP_TITLE=My App

Reading Env Variables

Access exposed variables through import.meta.env in Vite.

const apiUrl = import.meta.env.VITE_API_URL
console.log(apiUrl)
// https://api.example.com

Security Note on Env Vars

Anything exposed to client code is visible in the browser.

  • Never put secrets like private API keys in VITE_ variables
  • Only public, non-sensitive config belongs here
  • Keep real secrets on the server

Path Aliases

An alias shortens import paths. The common one maps @ to the src folder.

This avoids fragile relative paths like ../../components.

import { fileURLToPath, URL } from "node:url"
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url))
    }
  }
})

Using the Alias

Once configured, import from @/ instead of relative paths.

// Without alias
import Button from "../../components/Button.vue"

// With @ alias
import Button from "@/components/Button.vue"

Dev Server Options

The config file also tunes the dev server:

  • port which port to listen on
  • open auto-open the browser
  • proxy forward API requests to avoid CORS
export default defineConfig({
  server: {
    port: 3000,
    open: true,
    proxy: {
      "/api": "http://localhost:8000"
    }
  }
})

Quick Check

Test your understanding of Vite configuration.

Recap: Configuration and Plugins

You learned to configure a Vue project:

  • vite.config.js or vue.config.js hold settings
  • Add plugins to the plugins array
  • Use .env files with the VITE_ prefix
  • Read them via import.meta.env
  • Set the @ alias for clean imports

Next: template syntax and data binding.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “CLI Configuration and Plugins” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “CLI Configuration and Plugins”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 3 lessons in total.

What will I learn in “CLI Configuration and Plugins”?

Configure the CLI and add plugins to extend your project. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.

How long does the “CLI Configuration and Plugins” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Vue CLI Installation
  2. Generated Project Structure
  3. CLI Configuration and Plugins
← Back to Vue Academy