|
|
// @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,
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
}))
|