mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-23 15:59:47 +00:00
feat(adventure): add single-file build pipeline
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc --noEmit && vite build",
|
||||
"build": "tsc --noEmit && vite build && tsx scripts/inline-build.ts",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
@@ -30,7 +31,7 @@
|
||||
"executor": "nx:run-commands",
|
||||
"cache": true,
|
||||
"options": {
|
||||
"command": "vite build --config apps/architecture-adventure/vite.config.ts"
|
||||
"command": "tsc --noEmit && vite build --config apps/architecture-adventure/vite.config.ts && tsx apps/architecture-adventure/scripts/inline-build.ts"
|
||||
},
|
||||
"outputs": [
|
||||
"{projectRoot}/dist"
|
||||
|
||||
39
apps/architecture-adventure/scripts/inline-build.ts
Normal file
39
apps/architecture-adventure/scripts/inline-build.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { readFileSync, writeFileSync, readdirSync, existsSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const distDir = join(import.meta.dirname, '..', 'dist')
|
||||
const htmlPath = join(distDir, 'index.html')
|
||||
|
||||
let html = readFileSync(htmlPath, 'utf-8')
|
||||
|
||||
const assetsDir = join(distDir, 'assets')
|
||||
if (existsSync(assetsDir)) {
|
||||
const assets = readdirSync(assetsDir)
|
||||
|
||||
// Inline CSS files
|
||||
for (const file of assets) {
|
||||
if (file.endsWith('.css')) {
|
||||
const css = readFileSync(join(assetsDir, file), 'utf-8')
|
||||
html = html.replace(
|
||||
new RegExp(`<link[^>]*href="[./]*assets/${file}"[^>]*>`),
|
||||
`<style>${css}</style>`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Inline JS files
|
||||
for (const file of assets) {
|
||||
if (file.endsWith('.js')) {
|
||||
const js = readFileSync(join(assetsDir, file), 'utf-8')
|
||||
html = html.replace(
|
||||
new RegExp(`<script[^>]*src="[./]*assets/${file}"[^>]*></script>`),
|
||||
`<script type="module">${js}</script>`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeFileSync(htmlPath, html)
|
||||
|
||||
const sizeKB = (Buffer.byteLength(html) / 1024).toFixed(1)
|
||||
console.warn(`Single-file build complete: ${htmlPath} (${sizeKB} KB)`)
|
||||
@@ -17,5 +17,5 @@
|
||||
},
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["src/**/*.ts", "vite.config.ts"]
|
||||
"include": ["src/**/*.ts", "vite.config.ts", "scripts/**/*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user