feat: 添加ESLint支持并优化Vite配置
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,3 +22,4 @@ dist.rar
|
|||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
.eslintrc-auto-import.json
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"serve": "vite",
|
"serve": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview --port 8080 --host 0.0.0.0",
|
||||||
"serve:test": "vite --mode test",
|
"serve:test": "vite --mode test",
|
||||||
"build:test": "vite build --mode test_build",
|
"build:test": "vite build --mode test_build",
|
||||||
"serve:dev": "vite --mode dev",
|
"serve:dev": "vite --mode dev",
|
||||||
|
|||||||
@@ -50,12 +50,18 @@ export default defineConfig(({ mode }) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
dts: "src/auto-imports.d.ts",
|
dts: "src/auto-imports.d.ts",
|
||||||
|
// 添加 ESLint 支持
|
||||||
|
eslintrc: {
|
||||||
|
enabled: true,
|
||||||
|
filepath: "./.eslintrc-auto-import.json",
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
createSvgIconsPlugin({
|
createSvgIconsPlugin({
|
||||||
// 指定需要缓存的图标文件夹
|
// 指定需要缓存的图标文件夹
|
||||||
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
|
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
|
||||||
// 指定symbolId格式
|
// 指定symbolId格式
|
||||||
symbolId: "icon-[dir]-[name]",
|
symbolId: "icon-[dir]-[name]",
|
||||||
|
inject: "body-last", // 注入位置优化
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
css: {
|
css: {
|
||||||
@@ -78,6 +84,9 @@ export default defineConfig(({ mode }) => {
|
|||||||
port: mode === "production" ? 8060 : 10086, // 根据环境设置端口
|
port: mode === "production" ? 8060 : 10086, // 根据环境设置端口
|
||||||
open: true, // 自动打开浏览器
|
open: true, // 自动打开浏览器
|
||||||
strictPort: false, // 如果端口已被占用,则尝试下一个可用端口
|
strictPort: false, // 如果端口已被占用,则尝试下一个可用端口
|
||||||
|
hmr: {
|
||||||
|
overlay: true,
|
||||||
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": {
|
"/api": {
|
||||||
target: "http://192.168.1.7:5567",
|
target: "http://192.168.1.7:5567",
|
||||||
@@ -100,17 +109,49 @@ export default defineConfig(({ mode }) => {
|
|||||||
sourcemap: false, // 对应vue.config.js中的productionSourceMap: false
|
sourcemap: false, // 对应vue.config.js中的productionSourceMap: false
|
||||||
outDir: "dist",
|
outDir: "dist",
|
||||||
assetsDir: "assets",
|
assetsDir: "assets",
|
||||||
// 分包策略
|
target: "es2015", // 目标浏览器版本
|
||||||
|
minify: "terser", // 使用terser进行压缩
|
||||||
|
cssCodeSplit: true,
|
||||||
|
// reportCompressedSize: false, // 提升构建速度
|
||||||
|
terserOptions: {
|
||||||
|
compress: {
|
||||||
|
drop_console: true, // 删除console
|
||||||
|
drop_debugger: true, // 删除debugger
|
||||||
|
},
|
||||||
|
format: {
|
||||||
|
comments: false, // 删除注释
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 优化分包策略
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
manualChunks: {
|
manualChunks: {
|
||||||
vendor: ["vue", "vue-router", "vuex"],
|
vendor: ["vue", "vue-router"],
|
||||||
antd: ["ant-design-vue"],
|
antd: ["ant-design-vue"],
|
||||||
|
elementPlus: ["element-plus"],
|
||||||
utils: ["axios", "lodash-es"],
|
utils: ["axios", "lodash-es"],
|
||||||
|
// 添加更细粒度的分包
|
||||||
|
icons: ["@ant-design/icons-vue"],
|
||||||
},
|
},
|
||||||
|
// 优化文件命名
|
||||||
|
chunkFileNames: "js/[name]-[hash].js",
|
||||||
|
entryFileNames: "js/[name]-[hash].js",
|
||||||
|
assetFileNames: "[ext]/[name]-[hash].[ext]",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// 优化依赖预构建
|
||||||
|
optimizeDeps: {
|
||||||
|
include: [
|
||||||
|
"vue",
|
||||||
|
"vue-router",
|
||||||
|
"ant-design-vue",
|
||||||
|
"element-plus",
|
||||||
|
"axios",
|
||||||
|
"lodash-es",
|
||||||
|
],
|
||||||
|
exclude: ["@iconify/json"], // 排除大型JSON文件
|
||||||
|
},
|
||||||
// 定义全局常量替换
|
// 定义全局常量替换
|
||||||
define: {
|
define: {
|
||||||
__VUE_OPTIONS_API__: true,
|
__VUE_OPTIONS_API__: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user