refactor: organize features and standardize frontend tooling
Colocate feature views, components, stores, and upload logic; centralize shared map utilities without changing API behavior. Add ESLint, Prettier, EditorConfig, and VS Code settings; standardize four-space indentation and document the project structure and checks. Validation: npm run check, npm run build, and git diff --check.
This commit is contained in:
+55
-59
@@ -4,78 +4,74 @@ import { fileURLToPath, URL } from 'node:url'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
const publicRoutes = [
|
||||
'/',
|
||||
'/gallery',
|
||||
'/community',
|
||||
]
|
||||
const publicRoutes = ['/', '/gallery', '/community']
|
||||
|
||||
const DEFAULT_SITE_URL = 'http://localhost:5173'
|
||||
|
||||
function getSiteUrl(value?: string) {
|
||||
const siteUrl = new URL(value?.trim() || DEFAULT_SITE_URL)
|
||||
if (!['http:', 'https:'].includes(siteUrl.protocol)) {
|
||||
throw new Error('VITE_SITE_URL 必须使用 http 或 https 协议')
|
||||
}
|
||||
return siteUrl.href.replace(/\/$/, '')
|
||||
const siteUrl = new URL(value?.trim() || DEFAULT_SITE_URL)
|
||||
if (!['http:', 'https:'].includes(siteUrl.protocol)) {
|
||||
throw new Error('VITE_SITE_URL 必须使用 http 或 https 协议')
|
||||
}
|
||||
return siteUrl.href.replace(/\/$/, '')
|
||||
}
|
||||
|
||||
function seoFilesPlugin(siteUrl: string) {
|
||||
return {
|
||||
name: 'opencloud-seo-files',
|
||||
closeBundle() {
|
||||
mkdirSync('dist/.well-known', { recursive: true })
|
||||
return {
|
||||
name: 'opencloud-seo-files',
|
||||
closeBundle() {
|
||||
mkdirSync('dist/.well-known', { recursive: true })
|
||||
|
||||
const robots = [
|
||||
'User-agent: *',
|
||||
'Allow: /',
|
||||
'Disallow: /admin',
|
||||
'Disallow: /auth/',
|
||||
'Disallow: /login',
|
||||
'Disallow: /register',
|
||||
'Disallow: /upload',
|
||||
'Disallow: /encyclopedia',
|
||||
'Disallow: /profile/settings',
|
||||
`Sitemap: ${siteUrl}/sitemap.xml`,
|
||||
'',
|
||||
].join('\n')
|
||||
const robots = [
|
||||
'User-agent: *',
|
||||
'Allow: /',
|
||||
'Disallow: /admin',
|
||||
'Disallow: /auth/',
|
||||
'Disallow: /login',
|
||||
'Disallow: /register',
|
||||
'Disallow: /upload',
|
||||
'Disallow: /encyclopedia',
|
||||
'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 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')
|
||||
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)
|
||||
},
|
||||
}
|
||||
writeFileSync('dist/robots.txt', robots)
|
||||
writeFileSync('dist/sitemap.xml', sitemap)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), 'VITE_')
|
||||
const siteUrl = getSiteUrl(env.VITE_SITE_URL)
|
||||
const env = loadEnv(mode, process.cwd(), 'VITE_')
|
||||
const siteUrl = getSiteUrl(env.VITE_SITE_URL)
|
||||
|
||||
return {
|
||||
plugins: [vue(), tailwindcss(), seoFilesPlugin(siteUrl)],
|
||||
server: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
},
|
||||
preview: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
},
|
||||
}
|
||||
return {
|
||||
plugins: [vue(), tailwindcss(), seoFilesPlugin(siteUrl)],
|
||||
server: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
},
|
||||
preview: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user