chore: release binary front assets with cdn
This commit is contained in:
@@ -28,7 +28,16 @@ build:
|
||||
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY) main.go
|
||||
|
||||
# Build release version (Frontend + Backend with embedded assets)
|
||||
release: build-web
|
||||
release:
|
||||
cd web && npm ci && npm run build
|
||||
@mkdir -p bin
|
||||
rm -rf internal/static/dist
|
||||
cp -r web/dist internal/static/dist
|
||||
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) $(TAGS_WEB) -o $(BINARY) main.go
|
||||
|
||||
# Build release version (Frontend + Backend with embedded assets)
|
||||
release-binary:
|
||||
cd web && npm ci && VITE_RELEASE_OPTIMIZE=true npm run build
|
||||
@mkdir -p bin
|
||||
rm -rf internal/static/dist
|
||||
cp -r web/dist internal/static/dist
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ createApp(App)
|
||||
.use(router)
|
||||
.use(VueMonacoEditorPlugin, {
|
||||
paths: {
|
||||
vs: `${origin}${BASE_URL}/assets/vs`
|
||||
vs: __MONACO_CDN__ || `${origin}${BASE_URL}/assets/vs`
|
||||
}
|
||||
})
|
||||
.mount('#app')
|
||||
|
||||
Vendored
+1
@@ -4,6 +4,7 @@ declare global {
|
||||
__BASE_URL__?: string
|
||||
__API_VERSION__?: string
|
||||
}
|
||||
const __MONACO_CDN__: string | null
|
||||
}
|
||||
|
||||
export {}
|
||||
|
||||
+30
-1
@@ -44,11 +44,38 @@ const compressionPlugin = () => ({
|
||||
}
|
||||
} as const)
|
||||
|
||||
// Release optimization plugin to offload fonts to CDN
|
||||
const releaseOptimizePlugin = (isOptimize: boolean) => ({
|
||||
name: 'release-optimize-plugin',
|
||||
transformIndexHtml(html: string) {
|
||||
if (isOptimize) {
|
||||
return html.replace(
|
||||
'</head>',
|
||||
` <link rel="preconnect" href="https://fonts.geekzu.org">\n <link rel="stylesheet" href="https://fonts.geekzu.org/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&family=Noto+Sans+SC:wght@100..900&display=swap">\n </head>`
|
||||
)
|
||||
}
|
||||
return html
|
||||
},
|
||||
transform(code: string, id: string) {
|
||||
if (isOptimize && id.includes('index.css')) {
|
||||
return {
|
||||
code: code
|
||||
.replace(/@import\s+["']@fontsource-variable\/inter\/index\.css["'];/g, '/* Removed for CDN */')
|
||||
.replace(/@import\s+["']@fontsource-variable\/noto-sans-sc\/index\.css["'];/g, '/* Removed for CDN */')
|
||||
.replace(/@import\s+["']@fontsource-variable\/jetbrains-mono\/index\.css["'];/g, '/* Removed for CDN */'),
|
||||
map: null
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const isOptimize = process.env.VITE_RELEASE_OPTIMIZE === 'true'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
tailwindcss(),
|
||||
viteStaticCopy({
|
||||
!isOptimize && viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
src: 'node_modules/monaco-editor/min/vs',
|
||||
@@ -56,6 +83,7 @@ export default defineConfig({
|
||||
}
|
||||
]
|
||||
}),
|
||||
releaseOptimizePlugin(isOptimize),
|
||||
compressionPlugin(),
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
@@ -147,5 +175,6 @@ export default defineConfig({
|
||||
}
|
||||
},
|
||||
define: {
|
||||
__MONACO_CDN__: isOptimize ? JSON.stringify('https://registry.npmmirror.com/monaco-editor/0.52.0/files/min/vs') : 'null'
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user