72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
import { defineConfig } from 'vite'
|
|
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
|
|
const publicRoutes = [
|
|
'/',
|
|
'/encyclopedia',
|
|
'/gallery',
|
|
'/community',
|
|
]
|
|
|
|
function getSiteUrl() {
|
|
const explicitUrl = process.env.VITE_SITE_URL
|
|
const siteUrl = explicitUrl
|
|
return siteUrl
|
|
}
|
|
|
|
function seoFilesPlugin() {
|
|
return {
|
|
name: 'opencloud-seo-files',
|
|
closeBundle() {
|
|
const siteUrl = getSiteUrl()
|
|
mkdirSync('dist/.well-known', { recursive: true })
|
|
|
|
const robots = [
|
|
'User-agent: *',
|
|
'Allow: /',
|
|
'Disallow: /admin',
|
|
'Disallow: /auth/',
|
|
'Disallow: /login',
|
|
'Disallow: /register',
|
|
'Disallow: /upload',
|
|
'Disallow: /profile/settings',
|
|
`Sitemap: ${siteUrl}/sitemap.xml`,
|
|
'',
|
|
].join('\n')
|
|
|
|
const sitemapUrls = publicRoutes
|
|
.map(route => ` <url>\n <loc>${siteUrl}${route}</loc>\n </url>`)
|
|
.join('\n')
|
|
|
|
const sitemap = [
|
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
sitemapUrls,
|
|
'</urlset>',
|
|
'',
|
|
].join('\n')
|
|
|
|
writeFileSync('dist/robots.txt', robots)
|
|
writeFileSync('dist/sitemap.xml', sitemap)
|
|
},
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [vue(), tailwindcss(), seoFilesPlugin()],
|
|
server: {
|
|
proxy: {
|
|
'/api': 'http://localhost:3001',
|
|
'/uploads': 'http://localhost:3001',
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
})
|