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