74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
import { defineConfig, loadEnv } from 'vite'
|
|
import path from 'path'
|
|
import createVitePlugins from './vite/plugins'
|
|
export default defineConfig(({ mode, command }) => {
|
|
const env = loadEnv(mode, process.cwd())
|
|
const { VITE_APP_ENV } = env
|
|
const buildTime = new Date().getTime()
|
|
return {
|
|
base: VITE_APP_ENV === 'production' ? '/' : '/',
|
|
plugins: [
|
|
...createVitePlugins(env, command === 'build'),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
// 设置路径
|
|
'~': path.resolve(__dirname, './'),
|
|
// 设置别名
|
|
'@': path.resolve(__dirname, './src')
|
|
},
|
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
|
|
},
|
|
// vite 相关配置
|
|
server: {
|
|
port: 80,
|
|
host: true,
|
|
open: true,
|
|
proxy: {
|
|
'/dev-api': {
|
|
target: 'http://192.168.50.234:9080',
|
|
// target: 'http://192.168.50.11:9080',
|
|
// target: 'http://192.168.50.178:8080',
|
|
// target: 'http://192.168.50.99:8080',
|
|
changeOrigin: true,
|
|
rewrite: (p) => p.replace(/^\/dev-api/, '')
|
|
}
|
|
},
|
|
// proxy: {
|
|
// '/ff-api': {
|
|
// target: 'https://apiadmin.tt-gaming.com', // 线上接口地址
|
|
// changeOrigin: true, // 是否允许跨域
|
|
// pathRewrite: {
|
|
// '^/ff-api': '' // 如果你需要去掉前缀,例如将 /api/xxx 替换为 /xxx
|
|
// }
|
|
// }
|
|
// }
|
|
},
|
|
css: {
|
|
postcss: {
|
|
plugins: [
|
|
{
|
|
postcssPlugin: 'internal:charset-removal',
|
|
AtRule: {
|
|
charset: (atRule) => {
|
|
if (atRule.name === 'charset') {
|
|
atRule.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: 'assets/[name].[hash].js',
|
|
chunkFileNames: 'assets/[name].[hash].js',
|
|
assetFileNames: 'assets/[name].[hash].[ext]'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|