1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-04-30 22:29:01 +08:00
vue-naive-admin/vite.config.js

81 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**********************************
* @Author: Ronnie Zhang
* @LastEditor: Ronnie Zhang
* @LastEditTime: 2023/12/05 21:31:02
* @Email: zclzone@outlook.com
* Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
**********************************/
import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import simpleHtmlPlugin from 'vite-plugin-simple-html'
import VueDevTools from 'vite-plugin-vue-devtools'
import { pluginPagePathes, pluginIcons } from './build/plugin-isme'
export default defineConfig(({ command, mode }) => {
const isBuild = command === 'build'
const viteEnv = loadEnv(mode, process.cwd())
const { VITE_TITLE, VITE_PUBLIC_PATH, VITE_PROXY_TARGET } = viteEnv
return {
base: VITE_PUBLIC_PATH || '/',
plugins: [
VueDevTools(),
Vue(),
Unocss(),
AutoImport({
imports: ['vue', 'vue-router'],
dts: false,
}),
Components({
resolvers: [NaiveUiResolver()],
dts: false,
}),
simpleHtmlPlugin({
minify: isBuild,
inject: {
data: {
title: VITE_TITLE,
},
},
}),
// 自定义插件用于生成页面文件的path并添加到虚拟模块
pluginPagePathes(),
// 自定义插件用于生成自定义icon并添加到虚拟模块
pluginIcons(),
],
resolve: {
alias: {
'@': path.resolve(process.cwd(), 'src'),
'~': path.resolve(process.cwd()),
},
},
server: {
host: '0.0.0.0',
port: 3200,
open: false,
proxy: {
'/api': {
target: VITE_PROXY_TARGET,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp('^/api'), ''),
configure: (proxy, options) => {
// 配置此项可在响应头中看到请求的真实地址
proxy.on('proxyRes', (proxyRes, req) => {
proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
})
},
},
},
},
build: {
chunkSizeWarningLimit: 1024, // chunk 大小警告的限制单位kb
},
}
})