andengxitong/vite.config.ts
2024-06-21 15:52:52 +08:00

53 lines
1.4 KiB
TypeScript
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.

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import createVitePlugins from './vite/plugins'
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd())
console.log(env);
const alias = {
// 设置路径
'~': path.resolve(__dirname, './'),
// 设置别名
'@': path.resolve(__dirname, './src')
}
return {
// plugins: [vue()],
plugins: createVitePlugins(env, command === 'build'),
//解决“vite use `--host` to expose”
base: './',
server: {
port: 7001,
host: true,
open: true,
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
'/dev-api': {
target: "http://localhost:7000",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev-api/, '')
}
}
},
// 打包配置
build: {
sourcemap: command === 'build' ? false : 'inline',
outDir: 'dist', //指定输出目录
assetsDir: 'assets', //指定静态资源存储目录(相对于outDir)
// 将js、css文件分离到单独文件夹
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
},
resolve: {
//别名配置引用src路径下的东西可以通过@如import Layout from '@/layout/index.vue'
alias: alias
}
}
})