You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// @ts-expect-error connect-history-api-fallback 未提供类型声明
import history from 'connect-history-api-fallback'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import type { Plugin } from 'vite'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const laravelPublicAdmin = path.resolve(__dirname, '../backend/public/admin')
function spaHistoryFallback(): Plugin {
const middleware = history({ index: '/index.html' })
return {
name: 'spa-history-fallback',
configureServer(server) {
return () => {
server.middlewares.use(middleware)
}
},
configurePreviewServer(server) {
return () => {
server.middlewares.use(middleware)
}
},
}
}
// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
base: mode === 'production' ? '/admin/' : '/',
build: {
outDir: laravelPublicAdmin,
emptyOutDir: true,
},
plugins: [
vue(),
spaHistoryFallback(),
/** 勿在 dev 对 /frontend/prototype 挂 sirv会与 import prototype.css 冲突(返回 text/css 导致动态 import .vue 失败) */
viteStaticCopy({
targets: [
{
src: 'frontend/prototype/**/*',
dest: 'frontend/prototype',
rename: { stripBase: 2 },
},
],
}),
],
server: {
open: '/',
proxy: {
'/api': {
// cxxfds-service与本机 php artisan serve 端口一致8000 常被其它 Laravel 占用时改用 8001
target: 'http://127.0.0.1:8001',
changeOrigin: true,
},
},
},
preview: {
proxy: {
'/api': {
target: 'http://127.0.0.1:8001',
changeOrigin: true,
},
},
},
}))