mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
chore: 优化Vercel部署流程
This commit is contained in:
parent
678cc15390
commit
2e7e6588a8
5 changed files with 54 additions and 4 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -51,3 +51,8 @@ release
|
||||||
*.local
|
*.local
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
.turbo
|
.turbo
|
||||||
|
.env
|
||||||
|
packages/web/bundle-stats-renderer.html
|
||||||
|
packages/web/bundle-stats.html
|
||||||
|
vercel.json
|
||||||
|
.vercel
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev --host",
|
"dev": "vite dev --host",
|
||||||
"build": "vite build",
|
"build": "node ./scripts/build.web.mjs",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"test:ui": "vitest --ui",
|
"test:ui": "vitest --ui",
|
||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
|
|
|
||||||
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()
|
||||||
8
packages/web/vercel.example.json
Normal file
8
packages/web/vercel.example.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"rewrites": [
|
||||||
|
{
|
||||||
|
"source": "/netease/:match*",
|
||||||
|
"destination": "https://your-netease-api.example.com/:match*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -27,15 +27,15 @@ export default defineConfig({
|
||||||
base: '/',
|
base: '/',
|
||||||
build: {
|
build: {
|
||||||
target: process.env.IS_ELECTRON ? 'esnext' : 'modules',
|
target: process.env.IS_ELECTRON ? 'esnext' : 'modules',
|
||||||
sourcemap: process.env.NODE_ENV === 'debug',
|
sourcemap: true,
|
||||||
outDir: './dist',
|
outDir: './dist',
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
plugins: [
|
plugins: [
|
||||||
visualizer({
|
visualizer({
|
||||||
filename: './bundle-stats-renderer.html',
|
filename: './bundle-stats.html',
|
||||||
gzipSize: true,
|
gzipSize: true,
|
||||||
projectRoot: 'src/renderer',
|
projectRoot: './',
|
||||||
template: 'treemap',
|
template: 'treemap',
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue