style: 💄 注释格式优化
This commit is contained in:
parent
71a83c0769
commit
eac07c0093
|
|
@ -17,10 +17,9 @@ import UnoCSS from "unocss/vite";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const pathSrc = path.resolve(__dirname, "src");
|
const pathSrc = path.resolve(__dirname, "src");
|
||||||
/** 参考Vite官方配置: https://cn.vitejs.dev/config */
|
// 参考Vite官方: https://cn.vitejs.dev/config
|
||||||
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
const env = loadEnv(mode, process.cwd());
|
const env = loadEnv(mode, process.cwd());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|
@ -30,7 +29,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
css: {
|
css: {
|
||||||
// CSS 预处理器
|
// CSS 预处理器
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
//define global scss variable
|
// 定义全局 SCSS 变量
|
||||||
scss: {
|
scss: {
|
||||||
javascriptEnabled: true,
|
javascriptEnabled: true,
|
||||||
additionalData: `
|
additionalData: `
|
||||||
|
|
@ -40,19 +39,29 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0", // 允许IP访问
|
// 允许IP访问
|
||||||
port: Number(env.VITE_APP_PORT), // 应用端口
|
host: "0.0.0.0",
|
||||||
open: true, // 运行是否自动打开浏览器
|
// 应用端口 (默认:3000)
|
||||||
|
port: Number(env.VITE_APP_PORT),
|
||||||
|
// 运行是否自动打开浏览器
|
||||||
|
open: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
/** 接口代理解决跨域 */
|
/**
|
||||||
|
* 反向代理解决跨域配置
|
||||||
|
* http://localhost:3000/dev-api/users (F12可见请求路径) => http://localhost:8989/users (实际请求后端 API 路径)
|
||||||
|
*
|
||||||
|
* env.VITE_APP_BASE_API: /dev-api
|
||||||
|
* env.VITE_APP_TARGET_URL: http://localhost:8989
|
||||||
|
* env.VITE_APP_TARGET_BASE_API: ""
|
||||||
|
*/
|
||||||
[env.VITE_APP_BASE_API]: {
|
[env.VITE_APP_BASE_API]: {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
target: env.VITE_APP_TARGET_URL, // https://api.xxx.com
|
target: env.VITE_APP_TARGET_URL,
|
||||||
rewrite: (path) =>
|
rewrite: (path) =>
|
||||||
path.replace(
|
path.replace(
|
||||||
new RegExp("^" + env.VITE_APP_BASE_API), // ^/dev-api
|
new RegExp("^" + env.VITE_APP_BASE_API),
|
||||||
env.VITE_APP_TARGET_BASE_API // ""
|
env.VITE_APP_TARGET_BASE_API
|
||||||
), // 将 /dev-api 开头的请求转发至 target
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -61,31 +70,34 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
UnoCSS({
|
UnoCSS({
|
||||||
hmrTopLevelAwait: false,
|
hmrTopLevelAwait: false,
|
||||||
}),
|
}),
|
||||||
|
// 自动导入参考: https://github.com/sxzz/element-plus-best-practices/blob/main/vite.config.ts
|
||||||
AutoImport({
|
AutoImport({
|
||||||
|
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
|
||||||
imports: ["vue", "@vueuse/core"],
|
imports: ["vue", "@vueuse/core"],
|
||||||
|
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
|
||||||
|
resolvers: [ElementPlusResolver(), IconsResolver({})],
|
||||||
eslintrc: {
|
eslintrc: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
filepath: "./.eslintrc-auto-import.json",
|
filepath: "./.eslintrc-auto-import.json",
|
||||||
globalsPropValue: true,
|
globalsPropValue: true,
|
||||||
},
|
},
|
||||||
resolvers: [
|
|
||||||
ElementPlusResolver(), // 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
|
|
||||||
IconsResolver({}),
|
|
||||||
],
|
|
||||||
vueTemplate: true,
|
vueTemplate: true,
|
||||||
dts: false, // 配置文件生成位置(false:关闭自动生成)
|
// 配置文件生成位置(false:关闭自动生成)
|
||||||
|
dts: false,
|
||||||
// dts: "src/types/auto-imports.d.ts",
|
// dts: "src/types/auto-imports.d.ts",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Components({
|
Components({
|
||||||
resolvers: [
|
resolvers: [
|
||||||
ElementPlusResolver(), // 自动导入 Element Plus 组件
|
// 自动导入 Element Plus 组件
|
||||||
IconsResolver({
|
ElementPlusResolver(),
|
||||||
enabledCollections: ["ep"], // @iconify-json/ep 是 Element Plus 的图标库
|
// 自动注册图标组件
|
||||||
}),
|
IconsResolver({ enabledCollections: ["ep"] }),
|
||||||
],
|
],
|
||||||
dirs: ["src/**/components"], // 指定自定义组件位置(默认:src/components)
|
// 指定自定义组件位置(默认:src/components)
|
||||||
dts: false, // 配置文件位置(false:关闭自动生成)
|
dirs: ["src/**/components"],
|
||||||
|
// 配置文件位置 (false:关闭自动生成)
|
||||||
|
dts: false,
|
||||||
// dts: "src/types/components.d.ts",
|
// dts: "src/types/components.d.ts",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
@ -93,8 +105,10 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
autoInstall: true,
|
autoInstall: true,
|
||||||
}),
|
}),
|
||||||
createSvgIconsPlugin({
|
createSvgIconsPlugin({
|
||||||
iconDirs: [path.resolve(pathSrc, "assets/icons")], // 指定需要缓存的图标文件夹
|
// 指定需要缓存的图标文件夹
|
||||||
symbolId: "icon-[dir]-[name]", // 指定symbolId格式
|
iconDirs: [path.resolve(pathSrc, "assets/icons")],
|
||||||
|
// 指定symbolId格式
|
||||||
|
symbolId: "icon-[dir]-[name]",
|
||||||
}),
|
}),
|
||||||
viteMockServe({
|
viteMockServe({
|
||||||
ignore: /^\_/,
|
ignore: /^\_/,
|
||||||
|
|
@ -102,7 +116,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
enable: mode === "development",
|
enable: mode === "development",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
/** 预加载项目必需的组件 */
|
// 预加载项目必需的组件
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: [
|
include: [
|
||||||
"vue",
|
"vue",
|
||||||
|
|
@ -163,7 +177,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||||
"vue-i18n",
|
"vue-i18n",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// 构建
|
// 构建配置
|
||||||
build: {
|
build: {
|
||||||
chunkSizeWarningLimit: 2000, // 消除打包大小超过500kb警告
|
chunkSizeWarningLimit: 2000, // 消除打包大小超过500kb警告
|
||||||
minify: "terser", // Vite 2.6.x 以上需要配置 minify: "terser", terserOptions 才能生效
|
minify: "terser", // Vite 2.6.x 以上需要配置 minify: "terser", terserOptions 才能生效
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue