|
|
|
/**
|
|
|
|
* Author: Fu Guobin
|
|
|
|
* Date: 2022/12/28
|
|
|
|
* Last Modified by: Fu Guobin
|
|
|
|
* Last Modified time: 2023/09/15
|
|
|
|
* Copyright:Daniel(Fu Guobin)
|
|
|
|
* Description:vite配置
|
|
|
|
*/
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
import { UserConfig, ConfigEnv, loadEnv, defineConfig } from 'vite';
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite';
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
|
|
|
import Icons from 'unplugin-icons/vite';
|
|
|
|
import IconsResolver from 'unplugin-icons/resolver';
|
|
|
|
import path from 'path';
|
|
|
|
const pathSrc = path.resolve(__dirname, 'src');
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|
|
|
const env = loadEnv(mode, process.cwd());
|
|
|
|
return {
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': pathSrc,
|
|
|
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//静态资源处理
|
|
|
|
assetsInclude: '',
|
|
|
|
//控制台输出的级别 info 、warn、error、silent
|
|
|
|
logLevel: 'info',
|
|
|
|
// 设为false 可以避免 vite 清屏而错过在终端中打印某些关键信息
|
|
|
|
clearScreen: true,
|
|
|
|
//本地运行配置,以及反向代理配置
|
|
|
|
server: {
|
|
|
|
host: 'localhost',
|
|
|
|
https: false, //是否启用 http 2
|
|
|
|
cors: true, //为开发服务器配置 CORS , 默认启用并允许任何源
|
|
|
|
open: true, //服务启动时自动在浏览器中打开应用
|
|
|
|
port: Number(env.VITE_APP_PORT),
|
|
|
|
strictPort: false, //设为true时端口被占用则直接退出,不会尝试下一个可用端口
|
|
|
|
force: false, //是否强制依赖预构建
|
|
|
|
hmr: true, //配置HMR
|
|
|
|
proxy: {
|
|
|
|
'/dev-api': {
|
|
|
|
// target: 'http://172.1.2.132:9010/', //本地接口地址
|
|
|
|
// target: 'http://172.1.2.57:9010/', //本地接口地址
|
|
|
|
target: 'http://10.10.10.56:9010/', //线上测试接口地址
|
|
|
|
changeOrigin: true,
|
|
|
|
rewrite: path => path.replace(/^\/dev-api/, '')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// proxy: {
|
|
|
|
// [env.VITE_APP_BASE_API]: {
|
|
|
|
// // target: 'http://172.1.2.196:9010/', //本地接口地址
|
|
|
|
// target: 'http://172.1.2.158:9010/', //本地接口地址
|
|
|
|
// // target: 'http://10.10.10.56:9010/', //线上测试接口地址
|
|
|
|
// changeOrigin: true,
|
|
|
|
// rewrite: path => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
vue(),
|
|
|
|
AutoImport({
|
|
|
|
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
|
|
|
|
imports: ['vue', '@vueuse/core'],
|
|
|
|
eslintrc: {
|
|
|
|
enabled: false, // Default `false`
|
|
|
|
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
|
|
|
|
globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
|
|
|
|
},
|
|
|
|
resolvers: [
|
|
|
|
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
|
|
|
|
ElementPlusResolver(),
|
|
|
|
NaiveUiResolver(),
|
|
|
|
// 自动导入图标组件
|
|
|
|
IconsResolver({})
|
|
|
|
],
|
|
|
|
vueTemplate: true, // 是否在 vue 模板中自动导入
|
|
|
|
dts: path.resolve(pathSrc, 'types', 'auto-imports.d.ts') // (false) 配置文件生成位置,默认是根目录 /auto-imports.d.ts
|
|
|
|
}),
|
|
|
|
|
|
|
|
Components({
|
|
|
|
resolvers: [
|
|
|
|
// 自动注册图标组件
|
|
|
|
IconsResolver({
|
|
|
|
enabledCollections: ['ep'] //@iconify-json/ep 是 Element Plus 的图标库
|
|
|
|
}),
|
|
|
|
// 自动导入 Element Plus 组件
|
|
|
|
ElementPlusResolver(),
|
|
|
|
NaiveUiResolver()
|
|
|
|
],
|
|
|
|
dts: path.resolve(pathSrc, 'types', 'components.d.ts') // (false) 配置文件生成位置,默认是根目录 /components.d.ts
|
|
|
|
}),
|
|
|
|
|
|
|
|
Icons({
|
|
|
|
// 自动安装图标库
|
|
|
|
autoInstall: true
|
|
|
|
}),
|
|
|
|
|
|
|
|
createSvgIconsPlugin({
|
|
|
|
// 指定需要缓存的图标文件夹
|
|
|
|
iconDirs: [path.resolve(pathSrc, 'assets/icons')],
|
|
|
|
// 指定symbolId格式
|
|
|
|
symbolId: 'icon-[dir]-[name]'
|
|
|
|
})
|
|
|
|
],
|
|
|
|
css: {
|
|
|
|
// CSS 预处理器
|
|
|
|
preprocessorOptions: {
|
|
|
|
//define global scss variable
|
|
|
|
scss: {
|
|
|
|
javascriptEnabled: true,
|
|
|
|
additionalData: `
|
|
|
|
@use "@/styles/variables.scss" as *;
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// esbuild: {
|
|
|
|
// //打包时去除console和debugger代码
|
|
|
|
// drop: ['console', 'debugger']
|
|
|
|
// },
|
|
|
|
//打包配置
|
|
|
|
build: {
|
|
|
|
//浏览器兼容性 "esnext"|"modules"
|
|
|
|
target: 'modules',
|
|
|
|
//指定输出路径
|
|
|
|
outDir: 'dist',
|
|
|
|
//生成静态资源的存放路径
|
|
|
|
assetsDir: 'assets',
|
|
|
|
//小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项
|
|
|
|
assetsInlineLimit: 4096,
|
|
|
|
//启用/禁用 CSS 代码拆分
|
|
|
|
cssCodeSplit: true,
|
|
|
|
//构建后是否生成 source map 文件
|
|
|
|
sourcemap: false,
|
|
|
|
//自定义底层的 Rollup 打包配置
|
|
|
|
rollupOptions: {},
|
|
|
|
//@rollup/plugin-commonjs 插件的选项
|
|
|
|
commonjsOptions: {},
|
|
|
|
//当设置为 true,构建后将会生成 manifest.json 文件
|
|
|
|
manifest: false,
|
|
|
|
// 设置为 false 可以禁用最小化混淆,
|
|
|
|
// 或是用来指定使用哪种混淆器
|
|
|
|
// boolean | 'terser' | 'esbuild'
|
|
|
|
minify: 'terser', //terser 构建后文件体积更小
|
|
|
|
//传递给 Terser 的更多 minify 选项。
|
|
|
|
terserOptions: {
|
|
|
|
compress: {
|
|
|
|
//生产环境时移除console
|
|
|
|
drop_console: true,
|
|
|
|
drop_debugger: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//设置为 false 来禁用将构建后的文件写入磁盘
|
|
|
|
write: true,
|
|
|
|
//默认情况下,若 outDir 在 root 目录下,则 Vite 会在构建时清空该目录。
|
|
|
|
emptyOutDir: true,
|
|
|
|
//chunk 大小警告的限制
|
|
|
|
chunkSizeWarningLimit: 500
|
|
|
|
},
|
|
|
|
optimizeDeps: {
|
|
|
|
include: [
|
|
|
|
'vue',
|
|
|
|
'vue-router',
|
|
|
|
'pinia',
|
|
|
|
'axios',
|
|
|
|
'element-plus/es/components/form/style/css',
|
|
|
|
'element-plus/es/components/form-item/style/css',
|
|
|
|
'element-plus/es/components/button/style/css',
|
|
|
|
'element-plus/es/components/input/style/css',
|
|
|
|
'element-plus/es/components/input-number/style/css',
|
|
|
|
'element-plus/es/components/switch/style/css',
|
|
|
|
'element-plus/es/components/upload/style/css',
|
|
|
|
'element-plus/es/components/menu/style/css',
|
|
|
|
'element-plus/es/components/col/style/css',
|
|
|
|
'element-plus/es/components/icon/style/css',
|
|
|
|
'element-plus/es/components/row/style/css',
|
|
|
|
'element-plus/es/components/tag/style/css',
|
|
|
|
'element-plus/es/components/dialog/style/css',
|
|
|
|
'element-plus/es/components/loading/style/css',
|
|
|
|
'element-plus/es/components/radio/style/css',
|
|
|
|
'element-plus/es/components/radio-group/style/css',
|
|
|
|
'element-plus/es/components/popover/style/css',
|
|
|
|
'element-plus/es/components/scrollbar/style/css',
|
|
|
|
'element-plus/es/components/tooltip/style/css',
|
|
|
|
'element-plus/es/components/dropdown/style/css',
|
|
|
|
'element-plus/es/components/dropdown-menu/style/css',
|
|
|
|
'element-plus/es/components/dropdown-item/style/css',
|
|
|
|
'element-plus/es/components/sub-menu/style/css',
|
|
|
|
'element-plus/es/components/menu-item/style/css',
|
|
|
|
'element-plus/es/components/divider/style/css',
|
|
|
|
'element-plus/es/components/card/style/css',
|
|
|
|
'element-plus/es/components/link/style/css',
|
|
|
|
'element-plus/es/components/breadcrumb/style/css',
|
|
|
|
'element-plus/es/components/breadcrumb-item/style/css',
|
|
|
|
'element-plus/es/components/table/style/css',
|
|
|
|
'element-plus/es/components/tree-select/style/css',
|
|
|
|
'element-plus/es/components/table-column/style/css',
|
|
|
|
'element-plus/es/components/select/style/css',
|
|
|
|
'element-plus/es/components/option/style/css',
|
|
|
|
'element-plus/es/components/pagination/style/css',
|
|
|
|
'element-plus/es/components/tree/style/css',
|
|
|
|
'element-plus/es/components/alert/style/css',
|
|
|
|
|
|
|
|
'@vueuse/core',
|
|
|
|
'path-to-regexp',
|
|
|
|
'echarts',
|
|
|
|
'vue-i18n'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|