build:升级 Vite并添加兼容性支持

-将 Vite 升级到6.0.0 版本
- 添加 legacy 插件以支持旧版浏览器
- 引入 autoprefixer 以增强 CSS兼容性
- 更新 browserslist 以指定目标浏览器版本
- 在 main.ts 中引入 core-js 和 regenerator-runtime 以提供 Polyfill 支持
This commit is contained in:
陈昱达
2025-03-18 19:47:06 +08:00
parent 5583d2b856
commit 18c78e7fec
4 changed files with 1674 additions and 136 deletions

1785
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,7 @@
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"axios": "^1.8.2",
"core-js": "^3.41.0",
"cos-js-sdk-v5": "^1.8.7",
"dotenv": "^16.4.7",
"element-plus": "^2.7.8",
@@ -41,19 +42,29 @@
"@types/node": "^20.14.5",
"@types/postcss-pxtorem": "^6.1.0",
"@vant/auto-import-resolver": "^1.3.0",
"@vitejs/plugin-legacy": "^6.0.2",
"@vitejs/plugin-vue": "^5.0.5",
"@vitejs/plugin-vue-jsx": "^4.0.0",
"@vue/tsconfig": "^0.5.1",
"@yl/yili-fe-lint-config": "^1.0.0",
"amfe-flexible": "^2.2.1",
"autoprefixer": "^10.4.21",
"husky": "^9.1.5",
"npm-run-all2": "^6.2.0",
"postcss": "^8.5.3",
"postcss-pxtorem": "^6.1.0",
"sass": "^1.85.1",
"sass-loader": "^16.0.5",
"typescript": "~5.4.0",
"unplugin-auto-import": "^0.18.6",
"unplugin-vue-components": "^0.27.5",
"vite": "^5.3.1",
"vite": "^6.0.0",
"vue-tsc": "^2.0.21"
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie <= 11"
]
}

View File

@@ -4,6 +4,8 @@ import { createPinia } from 'pinia';
import App from './App.vue';
import router from './router';
import utils from '@/assets/js/common';
import 'core-js/stable';
import 'regenerator-runtime/runtime';
// 2. 引入组件样式
import 'vant/lib/index.css';
import '@/style/utils.scss';

View File

@@ -7,6 +7,8 @@ import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver, VantResolver } from 'unplugin-vue-components/resolvers';
import postCssPxToRem from 'postcss-pxtorem';
import legacy from '@vitejs/plugin-legacy';
import autoprefixer from 'autoprefixer';
export default defineConfig(({ mode }) => {
// 接收 mode 参数
// 正确加载环境变量
@@ -40,6 +42,7 @@ export default defineConfig(({ mode }) => {
css: {
postcss: {
plugins: [
autoprefixer(),
postCssPxToRem({
rootValue: 37.5,
propList: ['*']
@@ -54,7 +57,10 @@ export default defineConfig(({ mode }) => {
vue(),
vueJsx(),
AutoImport({ resolvers: [VantResolver(), ElementPlusResolver()] }),
Components({ resolvers: [VantResolver(), ElementPlusResolver()] })
Components({ resolvers: [VantResolver(), ElementPlusResolver()] }),
legacy({
targets: ['defaults', 'not IE 11'] // 根据需要调整目标浏览器
})
],
resolve: {
alias: {