# vue2-vite **Repository Path**: jxmlearner/vue2-vite ## Basic Information - **Project Name**: vue2-vite - **Description**: vite下创建vue2项目 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-10 - **Last Updated**: 2026-04-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 1. Node.js 16.15.0 与 Vite 的版本适配 Vite 官方对 Node 版本有明确要求,结合 Node 16.15.0 的特性和 Vite 各版本的兼容性: + Vite 2.x 系列:完全兼容 Node 16.15.0(Vite 2.x 要求 Node ≥ 12.2.0,16.15.0 远高于此),是最稳定的适配版本。 + Vite 3.x 系列:兼容 Node 16.15.0(Vite 3.x 要求 Node ≥ 14.18.0),但注意 Vite 3.2.0+ 对 Node 16 的兼容性更好。 + Vite 4.x 系列:不建议使用(Vite 4.x 要求 Node ≥ 14.18.0,但 Node 16.15.0 运行 Vite 4.x 可能出现部分隐性兼容问题,比如依赖安装、构建报错)。 + Vite 5.x 系列:完全不兼容(Vite 5.x 要求 Node ≥ 18.0.0,Node 16.15.0 达不到最低要求)。 推荐优先选择:Vite 2.9.x(如 2.9.16)或 Vite 3.2.x(如 3.2.7),这两个版本在 Node 16.15.0 下最稳定。 ```bash cnpm install vite@2.9.16 --save-dev ``` `package.json`中准备运行脚本: ```json { "name": "vite-ureport", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "vite": "^2.9.16" } } ``` `vite.config.js`的配置 ```js import { defineConfig } from 'vite' // import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ plugins: [ // vue() ], resolve: { alias: { '@': '/src' } }, server: { proxy: { '/ureport': { target: 'http://172.31.119.68:9001', changeOrigin: true // rewrite: (path) => path.replace(/^\/api/, '') }, '/dataSet': { target: 'http://172.31.119.68:9001', changeOrigin: true // rewrite: (path) => path.replace(/^\/api/, '') } } } }) ``` 上面的配置都是为了适配公司 ureport 报表的调试 ```bash # 安装 Vite 2.9.16(最适配) npm install vite@2.9.16 --save-dev # 安装对应版本的 @vitejs/plugin-vue npm install @vitejs/plugin-vue@2.3.4 --save-dev # 安装 Vue 3.2.x(配套版本) npm install vue@3.2.47 ```