feat(frontend): implement P0 optimization baseline
This commit is contained in:
@@ -8,6 +8,7 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const allowedHosts = parseAllowedHosts(env.VITE_ALLOWED_HOSTS)
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
@@ -28,11 +29,8 @@ export default defineConfig(({ mode }) => {
|
||||
},
|
||||
},
|
||||
server: {
|
||||
// 👇 加入这行,允许通过 IP 和网络访问
|
||||
host: true,
|
||||
// 👇 加入这行,允许所有外部域名(包括 Cloudflare 分配的域名)访问
|
||||
allowedHosts: true,
|
||||
|
||||
host: env.VITE_DEV_HOST === 'true',
|
||||
allowedHosts: env.VITE_ALLOW_ALL_HOSTS === 'true' ? true : allowedHosts,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: env.VITE_API_TARGET || 'http://localhost:3000',
|
||||
@@ -42,3 +40,12 @@ export default defineConfig(({ mode }) => {
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
function parseAllowedHosts(value?: string) {
|
||||
const hosts = value
|
||||
?.split(',')
|
||||
.map((host) => host.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
return hosts && hosts.length > 0 ? hosts : ['localhost', '127.0.0.1']
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user