2022-04-21 18:20:39 +08:00
|
|
|
|
import { UserConfigExport } from 'vite'
|
2022-04-21 17:14:30 +08:00
|
|
|
|
import path, { resolve } from 'path'
|
2022-04-21 14:14:40 +08:00
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
2022-04-21 17:14:30 +08:00
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
2022-04-20 22:40:26 +08:00
|
|
|
|
|
2022-04-21 00:50:12 +08:00
|
|
|
|
/** 配置项文档:https://vitejs.dev/config */
|
2022-04-21 18:20:39 +08:00
|
|
|
|
export default (): UserConfigExport => {
|
2022-04-21 00:50:12 +08:00
|
|
|
|
return {
|
2022-04-21 17:34:27 +08:00
|
|
|
|
/** build 打包时根据实际情况修改 base */
|
|
|
|
|
base: '/',
|
2022-04-21 00:50:12 +08:00
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
/** @ 符号指向 src 目录 */
|
2022-04-21 15:28:14 +08:00
|
|
|
|
'@': resolve(__dirname, './src')
|
|
|
|
|
}
|
2022-04-21 00:50:12 +08:00
|
|
|
|
},
|
2022-04-21 11:24:17 +08:00
|
|
|
|
server: {
|
|
|
|
|
/** 是否开启 https */
|
|
|
|
|
https: false,
|
|
|
|
|
/** host 设置为 true 才可以使用 network 的形式,以 ip 访问项目 */
|
|
|
|
|
host: true, // host: "0.0.0.0"
|
|
|
|
|
/** 端口号 */
|
|
|
|
|
port: 9999,
|
|
|
|
|
/** 是否自动打开浏览器 */
|
|
|
|
|
open: false,
|
|
|
|
|
/** 跨域设置允许 */
|
|
|
|
|
cors: true,
|
|
|
|
|
/** 如果端口已占用,直接退出 */
|
|
|
|
|
strictPort: true,
|
|
|
|
|
/** 接口代理 */
|
|
|
|
|
proxy: {
|
2022-04-21 14:14:40 +08:00
|
|
|
|
'/mock-api': {
|
|
|
|
|
target: 'https://vue-typescript-admin-mock-server-armour.vercel.app/mock-api',
|
2022-04-21 11:24:17 +08:00
|
|
|
|
ws: true,
|
|
|
|
|
/** 是否允许跨域 */
|
|
|
|
|
changeOrigin: true,
|
2022-04-21 15:28:14 +08:00
|
|
|
|
rewrite: (path) => path.replace('/mock-api', '')
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-21 11:24:17 +08:00
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
brotliSize: false,
|
|
|
|
|
/** 消除打包大小超过 500kb 警告 */
|
|
|
|
|
chunkSizeWarningLimit: 2000,
|
|
|
|
|
/** vite 2.6.x 以上需要配置 minify: terser,terserOptions 才能生效 */
|
2022-04-21 14:14:40 +08:00
|
|
|
|
minify: 'terser',
|
2022-04-21 11:24:17 +08:00
|
|
|
|
/** 在 build 代码时移除 console.log、debugger 和 注释 */
|
|
|
|
|
terserOptions: {
|
|
|
|
|
compress: {
|
|
|
|
|
drop_console: false,
|
|
|
|
|
drop_debugger: true,
|
2022-04-21 15:28:14 +08:00
|
|
|
|
pure_funcs: ['console.log']
|
2022-04-21 11:24:17 +08:00
|
|
|
|
},
|
|
|
|
|
output: {
|
|
|
|
|
/** 删除注释 */
|
2022-04-21 15:28:14 +08:00
|
|
|
|
comments: false
|
|
|
|
|
}
|
2022-04-21 11:24:17 +08:00
|
|
|
|
},
|
2022-04-21 14:14:40 +08:00
|
|
|
|
assetsDir: 'static/assets',
|
2022-04-21 11:24:17 +08:00
|
|
|
|
/** 静态资源打包到 dist 下的不同目录 */
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
2022-04-21 14:14:40 +08:00
|
|
|
|
chunkFileNames: 'static/js/[name]-[hash].js',
|
|
|
|
|
entryFileNames: 'static/js/[name]-[hash].js',
|
2022-04-21 15:28:14 +08:00
|
|
|
|
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-21 11:24:17 +08:00
|
|
|
|
},
|
2022-04-21 12:22:35 +08:00
|
|
|
|
/** vite 插件 */
|
|
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
|
|
|
|
/** 自动按需导入 */
|
|
|
|
|
AutoImport({
|
2022-04-21 13:25:02 +08:00
|
|
|
|
dts: './src/types/auto-imports.d.ts',
|
2022-04-21 15:28:14 +08:00
|
|
|
|
resolvers: [ElementPlusResolver()]
|
2022-04-21 12:22:35 +08:00
|
|
|
|
}),
|
|
|
|
|
/** 自动按需导入 */
|
|
|
|
|
Components({
|
2022-04-21 13:25:02 +08:00
|
|
|
|
dts: './src/types/components.d.ts',
|
2022-04-21 15:28:14 +08:00
|
|
|
|
resolvers: [ElementPlusResolver()]
|
2022-04-21 17:14:30 +08:00
|
|
|
|
}),
|
|
|
|
|
/** svg */
|
|
|
|
|
createSvgIconsPlugin({
|
|
|
|
|
iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
|
|
|
|
|
symbolId: 'icon-[dir]-[name]'
|
2022-04-21 15:28:14 +08:00
|
|
|
|
})
|
|
|
|
|
]
|
2022-04-21 00:50:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|