01
はじめに
プロジェクト作成
テンプレートを指定してプロジェクトを雛形生成します。
vite
# npm create vite@latest my-app -- --template vue
# npm create vite@latest my-app -- --template react-ts設定
プラグインを組み込んだ Vite の設定ファイルです。
vite
// vite.config.ts
import { defineConfig } from "vite";
export default defineConfig({
plugins: [vue()],
server: { port: 3000 },
});Dev/Build
主なコマンドは 3 つあります。
vite
# vite # dev server
# vite build # production build
# vite preview # preview build02
機能
Plugins
プラグインで Vite の機能を拡張します。
vite
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
});環境変数
VITE_ プレフィックスを付けた環境変数だけがクライアントに公開されます。
vite
import.meta.env.VITE_API_URL
// .env
VITE_API_URL=https://api.example.comProxy
開発中の API リクエストをプロキシできます。
vite
server: {
proxy: {
"/api": "http://localhost:8080",
},
}Was this helpful?