Skip to content

Vite Folha de referência

Ferramenta de build frontend de nova geração com inicialização instantânea do servidor.

01

Primeiros Passos

Criar

Crie projetos a partir de templates.

vite
# npm create vite@latest my-app -- --template vue
# npm create vite@latest my-app -- --template react-ts

Configuração

Configuração do Vite com plugins.

vite
// vite.config.ts
import { defineConfig } from "vite";

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

Dev/Build

Três comandos principais.

vite
# vite        # dev server
# vite build  # production build
# vite preview # preview build
02

Recursos

Plugins

Plugins estendem a funcionalidade do Vite.

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

export default defineConfig({
  plugins: [react()],
});

Variáveis de Ambiente

O prefixo VITE_ expõe variáveis de ambiente ao cliente.

vite
import.meta.env.VITE_API_URL

// .env
VITE_API_URL=https://api.example.com

Proxy

Faça proxy de requisições de API durante o desenvolvimento.

vite
server: {
  proxy: {
    "/api": "http://localhost:8080",
  },
}

Was this helpful?