Skip to content

Commit ec079e4

Browse files
committed
feat(web): bundle assets into single html with vite-plugin-singlefile
1 parent 450bbf1 commit ec079e4

9 files changed

Lines changed: 113 additions & 31 deletions

File tree

install.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@ Invoke-WebRequest -Uri "$serveUrl`?ts=$ts" -OutFile $servePath -UseBasicParsing
5656
# Prepare web dashboard assets to $OROIO_DIR\web
5757
Write-Info "Preparing web dashboard assets..."
5858
$webDst = Join-Path $OROIO_DIR "web"
59-
$assetsDst = Join-Path $webDst "assets"
6059
if (-not (Test-Path $webDst)) { New-Item -ItemType Directory -Path $webDst -Force | Out-Null }
61-
if (-not (Test-Path $assetsDst)) { New-Item -ItemType Directory -Path $assetsDst -Force | Out-Null }
6260

6361
$webBase = "https://github.com/notdp/oroio/releases/download/web-dist"
6462
try {
6563
Invoke-WebRequest -Uri "$webBase/index.html`?ts=$ts" -OutFile (Join-Path $webDst "index.html") -UseBasicParsing
66-
Invoke-WebRequest -Uri "$webBase/index.js`?ts=$ts" -OutFile (Join-Path $assetsDst "index.js") -UseBasicParsing
67-
Invoke-WebRequest -Uri "$webBase/index.css`?ts=$ts" -OutFile (Join-Path $assetsDst "index.css") -UseBasicParsing
6864
}
6965
catch {
7066
Write-Warn "Failed to download web assets: $($_.Exception.Message)"

install.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,14 @@ fetch_component() {
5959
fetch_web_assets() {
6060
make_tmpdir
6161
WEB_DIR="$DK_TMPDIR/web"
62-
install -d "$WEB_DIR/assets"
62+
install -d "$WEB_DIR"
6363

6464
local base="https://github.com/notdp/oroio/releases/download/web-dist"
6565
local ts
6666
ts=$(date +%s)
6767
printf '正在下载 web 资源...\n'
6868
curl -fsSL -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' "${base}/index.html?ts=${ts}" \
6969
-o "$WEB_DIR/index.html" || die "下载 index.html 失败"
70-
curl -fsSL -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' "${base}/index.js?ts=${ts}" \
71-
-o "$WEB_DIR/assets/index.js" || die "下载 index.js 失败"
72-
curl -fsSL -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' "${base}/index.css?ts=${ts}" \
73-
-o "$WEB_DIR/assets/index.css" || die "下载 index.css 失败"
7470
}
7571

7672
locate_sources() {

web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
5+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%201024%22%3E%3Crect%20width%3D%221024%22%20height%3D%221024%22%20rx%3D%22200%22%20fill%3D%22%231a1a1a%22%2F%3E%3Cg%20fill%3D%22%23ef4444%22%3E%3Crect%20x%3D%22200%22%20y%3D%22320%22%20width%3D%2264%22%20height%3D%22384%22%2F%3E%3Crect%20x%3D%22264%22%20y%3D%22320%22%20width%3D%22128%22%20height%3D%2264%22%2F%3E%3Crect%20x%3D%22264%22%20y%3D%22640%22%20width%3D%22128%22%20height%3D%2264%22%2F%3E%3Crect%20x%3D%22392%22%20y%3D%22384%22%20width%3D%2264%22%20height%3D%22256%22%2F%3E%3Crect%20x%3D%22520%22%20y%3D%22320%22%20width%3D%2264%22%20height%3D%22384%22%2F%3E%3Crect%20x%3D%22584%22%20y%3D%22448%22%20width%3D%2264%22%20height%3D%22128%22%2F%3E%3Crect%20x%3D%22648%22%20y%3D%22320%22%20width%3D%2264%22%20height%3D%22128%22%2F%3E%3Crect%20x%3D%22648%22%20y%3D%22576%22%20width%3D%2264%22%20height%3D%22128%22%2F%3E%3Crect%20x%3D%22712%22%20y%3D%22320%22%20width%3D%2264%22%20height%3D%2264%22%2F%3E%3Crect%20x%3D%22712%22%20y%3D%22640%22%20width%3D%2264%22%20height%3D%2264%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>oroio</title>
88
<script type="module">

web/package-lock.json

Lines changed: 95 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"tw-animate-css": "^1.4.0",
4848
"typescript": "~5.9.3",
4949
"typescript-eslint": "^8.46.4",
50-
"vite": "^7.2.4"
50+
"vite": "^7.2.4",
51+
"vite-plugin-singlefile": "^2.3.0"
5152
}
5253
}

web/public/favicon.png

-2.14 KB
Binary file not shown.

web/public/favicon.svg

Lines changed: 0 additions & 15 deletions
This file was deleted.

web/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

web/vite.config.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import tailwindcss from '@tailwindcss/vite'
4+
import { viteSingleFile } from 'vite-plugin-singlefile'
45
import fs from 'fs'
56
import path from 'path'
67
import { fileURLToPath } from 'url'
@@ -340,19 +341,27 @@ Command instructions here.
340341

341342
export default defineConfig({
342343
base: './',
343-
plugins: [react(), tailwindcss(), oroioDataPlugin(), factoryApiPlugin()],
344+
plugins: [
345+
react(),
346+
tailwindcss(),
347+
viteSingleFile({ removeViteModuleLoader: true }),
348+
oroioDataPlugin(),
349+
factoryApiPlugin(),
350+
],
344351
resolve: {
345352
alias: {
346353
'@': path.resolve(__dirname, './src'),
347354
},
348355
},
349356
build: {
350357
outDir: 'dist',
358+
assetsInlineLimit: 100000000,
359+
chunkSizeWarningLimit: 100000000,
360+
cssCodeSplit: false,
351361
rollupOptions: {
352362
output: {
353-
entryFileNames: 'assets/index.js',
354-
chunkFileNames: 'assets/[name].js',
355-
assetFileNames: 'assets/[name].[ext]',
363+
inlineDynamicImports: true,
364+
manualChunks: undefined,
356365
},
357366
},
358367
},

0 commit comments

Comments
 (0)