构建产物收敛到 assets/GVSite 子目录:vite assetsDir=GVSite,deploy 同步到 TempLate/assets/GVSite 并改写 index.html 引用
This commit is contained in:
1 parent
16879188f4
commit
42ccb20fe6
2 files changed
+26
-22
No files matched your search
+24
-22
@@ -110,18 +110,13 @@ if (Test-Path $DistDir) {
|
||||
Remove-Item -Recurse -Force $DistDir
|
||||
Write-Host " 已删除: $DistDir"
|
||||
}
|
||||
# 清理 TempLate/assets 中 GVSite 的旧产物(避免旧 hash 文件堆积/被误引用)
|
||||
$ProdAssets = Join-Path $TemplateRoot 'assets'
|
||||
if (Test-Path $ProdAssets) {
|
||||
$GvsitePatterns = @('index-*', '*View-*', 'SiteLayout-*', 'HomeView-*', 'AboutView-*', 'Error*View-*', 'Invite*View-*', 'Project*View-*', 'Member*View-*', 'YuanZeView-*', 'BSmoothView-*', 'TermiNexusView-*', 'UnauthorizedView-*', 'UserCardView-*', 'LoginView-*', 'RegisterView-*', 'GalleryView-*', 'ContactView-*', 'MembersView-*', 'DocumentView-*', 'IntegrityReportView-*', 'ServiceView-*', 'QuotationView-*', 'SmanageView-*', 'ResourceShareView-*', 'CollaborativeCodingView-*', 'RecruitingView-*', 'ApplyView-*', 'InterviewView-*', 'Ying_Right-*', '_plugin-vue_export-helper-*', 'fa-*')
|
||||
$OldCount = 0
|
||||
foreach ($pattern in $GvsitePatterns) {
|
||||
Get-ChildItem -Path $ProdAssets -Filter $pattern -File -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
Remove-Item -Force $_.FullName
|
||||
$OldCount++
|
||||
}
|
||||
}
|
||||
Write-Host " 清理旧产物: $OldCount 个"
|
||||
# 清理 TempLate/assets/GVSite 旧产物目录(构建产物统一收敛到该子目录)
|
||||
$ProdGvsiteDir = Join-Path $TemplateRoot 'assets\GVSite'
|
||||
if (Test-Path $ProdGvsiteDir) {
|
||||
Get-ChildItem -Path $ProdGvsiteDir -Recurse -Force | Remove-Item -Recurse -Force
|
||||
Write-Host " 已清理旧产物目录: assets/GVSite/"
|
||||
} else {
|
||||
Write-Host " assets/GVSite 目录不存在,跳过" -ForegroundColor DarkGray
|
||||
}
|
||||
Write-Host ''
|
||||
|
||||
@@ -146,22 +141,29 @@ Write-Host ''
|
||||
# =====================
|
||||
Write-Host '[4/6] 同步产物到 www 生产目录...' -ForegroundColor Yellow
|
||||
|
||||
# 复制 assets(GVSite 的构建产物带有 hash,先清理旧的再复制避免堆积)
|
||||
$DistAssets = Join-Path $DistDir 'assets'
|
||||
if (Test-Path $DistAssets) {
|
||||
if (-not (Test-Path $ProdAssets)) {
|
||||
New-Item -ItemType Directory -Path $ProdAssets -Force | Out-Null
|
||||
# 复制 GVSite 构建产物到生产目录 assets/GVSite/(vite assetsDir=GVSite,产物位于 dist/GVSite/)
|
||||
$ProdGvsite = Join-Path $TemplateRoot 'assets\GVSite'
|
||||
$DistGvsite = Join-Path $DistDir 'GVSite'
|
||||
if (Test-Path $DistGvsite) {
|
||||
if (-not (Test-Path $ProdGvsite)) {
|
||||
New-Item -ItemType Directory -Path $ProdGvsite -Force | Out-Null
|
||||
}
|
||||
Copy-Item -Recurse -Force (Join-Path $DistAssets '*') $ProdAssets
|
||||
Write-Host " 已同步: assets/"
|
||||
# 先清空旧产物,避免 hash 文件堆积
|
||||
Get-ChildItem -Path $ProdGvsite -File -ErrorAction SilentlyContinue | Remove-Item -Force
|
||||
Copy-Item -Recurse -Force (Join-Path $DistGvsite '*') $ProdGvsite
|
||||
Write-Host " 已同步: assets/GVSite/"
|
||||
} else {
|
||||
Write-Warning " dist 中未找到 assets/GVSite,请检查 vite.config.ts 的 base 配置"
|
||||
}
|
||||
|
||||
# 复制 index.html
|
||||
# 复制 index.html(并把产物引用 /GVSite/ 改为实际部署位置 /assets/GVSite/)
|
||||
$DistIndex = Join-Path $DistDir 'index.html'
|
||||
$ProdIndex = Join-Path $TemplateRoot 'index.html'
|
||||
if (Test-Path $DistIndex) {
|
||||
Copy-Item -Force $DistIndex $ProdIndex
|
||||
Write-Host " 已同步: index.html"
|
||||
$indexHtml = Get-Content $DistIndex -Raw
|
||||
$indexHtml = $indexHtml -replace '/GVSite/', '/assets/GVSite/'
|
||||
Set-Content -Path $ProdIndex -Value $indexHtml -Encoding UTF8 -NoNewline
|
||||
Write-Host " 已同步: index.html(引用已改写为 /assets/GVSite/)"
|
||||
}
|
||||
|
||||
Write-Host ' 同步完成'
|
||||
|
||||
@@ -34,5 +34,7 @@ export default defineConfig({
|
||||
outDir: 'dist',
|
||||
sourcemap: false,
|
||||
chunkSizeWarningLimit: 1500,
|
||||
// 构建产物收敛到 dist/GVSite/*,部署时同步到 TempLate/assets/GVSite
|
||||
assetsDir: 'GVSite',
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user