mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 13:48:02 +00:00
chore: 优化Vercel部署流程
This commit is contained in:
parent
678cc15390
commit
2e7e6588a8
5 changed files with 54 additions and 4 deletions
37
packages/web/scripts/build.web.mjs
Normal file
37
packages/web/scripts/build.web.mjs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { build } from 'vite'
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
const main = async () => {
|
||||
const api = process.env.VITE_APP_NETEASE_API_URL || ''
|
||||
const rewriteApi = process.env.NETEASE_API_URL_FOR_REWRITE || ''
|
||||
|
||||
/**
|
||||
* 使用 Vercel 的 rewrite 功能来帮我们解决跨域的问题
|
||||
* @see https://vercel.com/docs/project-configuration#project-configuration/rewrites
|
||||
*/
|
||||
if (process.env.VERCEL && api === '/netease') {
|
||||
console.log(`VITE_APP_NETEASE_API_URL: ${api}`)
|
||||
console.log(`NETEASE_API_URL_FOR_REWRITE: ${rewriteApi}`)
|
||||
|
||||
if (!rewriteApi.startsWith('http')) {
|
||||
throw new Error('NETEASE_API_URL_FOR_REWRITE must start with http')
|
||||
}
|
||||
|
||||
const vercelConfig = JSON.parse(await fs.readFile('./vercel.example.json'))
|
||||
vercelConfig.rewrites[0].destination = `${rewriteApi}${
|
||||
rewriteApi.endsWith('/') ? '' : '/'
|
||||
}:match*`
|
||||
|
||||
console.log('vercel.json 👇')
|
||||
console.log(vercelConfig)
|
||||
|
||||
await fs.writeFile(
|
||||
'../../vercel.json',
|
||||
JSON.stringify(vercelConfig, null, 2)
|
||||
)
|
||||
}
|
||||
|
||||
await build()
|
||||
}
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue