vitevite 的基本使用使用 vite 创建项目使用 pnpmshell自动换行复制pnpm create vite 使用官方的模版shell自动换行复制pnpm create vite vite-program -- --template vue-ts 生成好项目后你可以看到项目中有一个 vite.config.ts的文件,在这里我们可以进行一系列的配置配置路径别名安装类型声明文件bash自动换行复制pnpm i -D @type/node 将 @ 指向 src 文件js自动换行复制import path from "node:path" import vue from "@vitejs/plugin-vue" import { defineConfig } from "vite" export default defineConfig({ plugins: [vue()], resolve: { alias: { "@": path.resolve(__dirname, "src") }, }, }) 配置代理js自动换行复制export default defineConfig({ server: { proxy: { // string shorthand "/foo": "http://localhost:4567", // with options "/api": { target: "http://jsonplaceholder.typicode.com", changeOrigin: true, rewrite: path => path.replace(/^\/api/, ""), }, // with RegEx "^/fallback/.*": { target: "http://jsonplaceholder.typicode.com", changeOrigin: true, rewrite: path => path.replace(/^\/fallback/, ""), }, // Using the proxy instance "/api/": { target: "http://jsonplaceholder.typicode.com", changeOrigin: true, configure: (proxy, options) => { // proxy will be an instance of 'http-proxy' }, }, // Proxying websockets or socket.io "/socket.io": { target: "ws://localhost:3000", ws: true, }, }, }, }) 34 行配置项目端口及自动启动js自动换行复制export default defineConfig({ server: { port: 3030, // 服务启动端口 open: true, // 服务启动自动打开默认浏览器 }, }) 配置插件在 Vue.js 中写 Jsxbash自动换行复制pnpm i -D @vitejs/plugin-vue-jsx js自动换行复制import vue from "@vitejs/plugin-vue" import vueJsx from "@vitejs/plugin-vue-jsx" import { defineConfig } from "vite" export default defineConfig({ plugins: [vue(), vueJsx()], })
评论区
评论加载中...