mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-08 12:57:11 +08:00
first commit
This commit is contained in:
65
vite.config.ts
Normal file
65
vite.config.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import { fileURLToPath, URL } from 'url'
|
||||
import createVitePlugins from './config/plugins'
|
||||
|
||||
export default defineConfig(({ command, mode }) => {
|
||||
const env = loadEnv(mode, process.cwd()) as ImportMetaEnv
|
||||
|
||||
return {
|
||||
// 开发或生产环境服务的公共基础路径
|
||||
base: env.VITE_BASE,
|
||||
// 路径别名
|
||||
resolve: {
|
||||
alias: {
|
||||
'~': fileURLToPath(new URL('./', import.meta.url)),
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
// 引入sass全局样式变量
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
additionalData: `@import "@/styles/var.scss";`
|
||||
}
|
||||
}
|
||||
},
|
||||
server: {
|
||||
// 服务启动时是否自动打开浏览器
|
||||
open: true,
|
||||
// 本地跨域代理 -> 代理到服务器的接口地址
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: env.VITE_API_BASE_URL, // 后台服务器地址
|
||||
changeOrigin: true, // 是否允许不同源
|
||||
secure: false, // 支持https
|
||||
rewrite: (path) => path.replace(/^\/api/, '/')
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: createVitePlugins(env, command === 'build'),
|
||||
// 构建
|
||||
build: {
|
||||
chunkSizeWarningLimit: 2000, // 消除打包大小超过500kb警告
|
||||
outDir: 'dist', // 指定打包路径,默认为项目根目录下的dist目录
|
||||
minify: 'terser', // Vite 2.6.x 以上需要配置 minify:"terser",terserOptions才能生效
|
||||
terserOptions: {
|
||||
compress: {
|
||||
keep_infinity: true, // 防止 Infinity 被压缩成 1/0,这可能会导致 Chrome 上的性能问题
|
||||
drop_console: true, // 生产环境去除 console
|
||||
drop_debugger: true // 生产环境去除 debugger
|
||||
},
|
||||
format: {
|
||||
comments: false // 删除注释
|
||||
}
|
||||
},
|
||||
// 静态资源打包到dist下的不同目录
|
||||
rollupOptions: {
|
||||
output: {
|
||||
chunkFileNames: 'static/js/[name]-[hash].js',
|
||||
entryFileNames: 'static/js/[name]-[hash].js',
|
||||
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user