Home

Awesome

Use Vite Today

out-of-the-box for vue-cli projects without any codebase modifications.

<a href="https://github.com/IndexXuan/vue2-final-boilerplate" target="_blank" rel="noreferer nofollow">demo/boilerplate</a>

<p align="center"> <img src="./logo.png" alt="logo" title="logo" width="300px" /> </p> <p align="center"> <!-- <a href="https://github.com/IndexXuan/vue-cli-plugin-vite/actions/workflows/npm-publish.yml"> --> <!-- <img alt="NPM Publish" src="https://github.com/IndexXuan/vue-cli-plugin-vite/actions/workflows/npm-publish.yml/badge.svg?branch=main" style="max-width:100%;"> --> <!-- </a> --> <img alt="wakatime" src="https://wakatime.com/badge/github/IndexXuan/vue-cli-plugin-vite.svg" /> <a href="https://www.npmjs.com/package/vue-cli-plugin-vite" rel="nofollow" target="_blank"> <img alt="npm version" src="https://img.shields.io/npm/v/vue-cli-plugin-vite.svg" style="max-width:100%;"> </a> <a href="https://www.npmjs.com/package/vue-cli-plugin-vite" rel="nofollow" target="_blank"> <img alt="downloads" src="https://img.shields.io/npm/dt/vue-cli-plugin-vite.svg" style="max-width:100%;"> </a> <a href="https://www.npmjs.com/package/vue-cli-plugin-vite" rel="nofollow" target="_blank"> <img alt="download monthly" src="https://img.shields.io/npm/dm/vue-cli-plugin-vite.svg" style="max-width:100%;"> </a> <br /> <a href="https://github.com/IndexXuan/vue-cli-plugin-vite/actions/workflows/ci.yml" target="_blank"> <img alt="CI" src="https://github.com/IndexXuan/vue-cli-plugin-vite/actions/workflows/ci.yml/badge.svg" style="max-width:100%;"> </a> <!-- <a href="https://github.com/IndexXuan/vue-cli-plugin-vite#readme"> --> <!-- <img alt="Documentation" src="https://img.shields.io/badge/Doc-yes-brightgreen.svg" style="max-width:100%;"> --> <!-- </a> --> <a href="https://github.com/IndexXuan/vue-cli-plugin-vite/graphs/commit-activity" target="_blank"> <img alt="Maintenance" src="https://img.shields.io/badge/Maintained-yes-green.svg" style="max-width:100%;"> </a> <a href="https://github.com/IndexXuan/vue-cli-plugin-vite/blob/main/LICENSE" target="_blank"> <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" style="max-width:100%;"> </a> <!-- <a href="https://twitter.com/indexxuan" rel="nofollow"> --> <!-- <img alt="Twitter: IndexXuan" src="https://img.shields.io/twitter/follow/indexxuan.svg?style=social" style="max-width:100%;"> --> <!-- </a> --> </p>

Table of Contents

<!-- toc --> <!-- tocstop -->

Usage

# 1. first step
vue add vite

# 2. second step
# NOTE you cannot directly use `vite` or `npx vite` since it is origin vite not this plugin.
yarn vite // or npm run vite

# 3. add optimizeDeps#include (optional and will speedup devServer start time a lot)
# added in vue.config.js#pluginOptions.vite.optimizeDeps.include
# e.g.: ['vue', 'vue-router', 'vuex']
# all scanned deps(logged in terminal) can be added for speedup.

Motivation

Options

// vue.config.js
{
  // ...
  pluginOptions: {
    vite: {
      /**
       * Plugin[]
       * @default []
       */
      plugins: [], // other vite plugins list, will be merge into this plugin\'s underlying vite.config.ts
      /**
       * Vite UserConfig.optimizeDeps options
       * recommended set `include` for speedup page-loaded time, e.g. include: ['vue', 'vue-router', '@scope/xxx']
       * @default {}
       */
      optimizeDeps: {},
      /**
       * type-checker, recommended disabled for large-scale old project.
       * @default false
       */
      disabledTypeChecker: true,
      /**
       * lint code by eslint
       * @default false
       */
      disabledLint: false,
    }
  },
}

Underlying principle

Compatibility

Differences between vue-cli and vite

Dimensionvue-clivite
Plugin1. based on webpack. <br />2. have service and generator lifecycles. <br />3. hooks based on each webpack plugin hooks1. based on rollup. <br />2. no generator lifecycle. <br />3. universal hooks based on rollup plugin hooks and vite self designed
Environment Variables1. loaded on process.env. <br />2. prefixed by VUE_APP_. <br />3. client-side use process.env.VUE_APP_XXX by webpack definePlugin1. not loaded on process.env. <br />2. prefixed by VITE_. <br />3. client-side use import.meta.env.VITE_XXX by vite inner define plugin
Entry Files1. main.{js,ts}.1. *.html
Config File1. vue.config.js1. vite.config.ts. <br />2. support use --config to locate
MPA Support1. native support by options.pages. <br />2. with history rewrite support1. native support by rollupOptions.input
Special Syntax1. require(by webpack) <br /> 2. require.context(by webpack) <br />2. use ~some-module/dist/index.css(by css-loader) <br />3. module.hot for HMR1. import.meta.glob/globEager <br />2. native support by vite, use module/dist/index.css directly <br />3. import.meta.hot for HMR
Local devServer1. webpack dev-server <br />2. express-style middleware and many extension api.1. connect <br />2. connect middleware
Type Checker1. fork-ts-checker-webpack-plugin1. No built-in, we can use vite-plugin-checker(based on vetur and vue-tsc)
Lint1. @vue/cli-plugin-eslint1. No built-in we can use vite-plugin-eslint,
Jest1. @vue/cli-plugin-jest1. will have first-class jest support

Milestones

Examples

you can clone/fork this repo, under examples/*

Troubleshooting

Benefits

Best development-experience right now

Migration to vite smoothly

Lint the codebase

Use vue-cli ecosystem

Relevant Vite Plugins