@mednours/fronton 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-report/index.d.ts +27 -0
- package/dist/bundle-report/index.d.ts.map +1 -0
- package/dist/client.d.ts +50 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +115 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -0
- package/package.json +9 -9
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export interface BundleReportOptions {
|
|
3
|
+
/** Warn when an uncompressed JS/CSS asset exceeds this size in KB. Defaults to 250. */
|
|
4
|
+
warnThresholdKb?: number;
|
|
5
|
+
/** Disable console output while still collecting metrics (e.g. in custom reporters/tests). */
|
|
6
|
+
silent?: boolean;
|
|
7
|
+
/** Optional callback receiving the computed chunk entries sorted largest-first. */
|
|
8
|
+
onReport?: (entries: BundleAssetReport[]) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface BundleAssetReport {
|
|
11
|
+
fileName: string;
|
|
12
|
+
rawBytes: number;
|
|
13
|
+
gzipBytes: number;
|
|
14
|
+
oversized: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Computes raw and gzip byte sizes for every emitted JS/CSS bundle asset. */
|
|
17
|
+
export declare function summarizeBundleAssets(bundle: Record<string, {
|
|
18
|
+
type: string;
|
|
19
|
+
code?: string;
|
|
20
|
+
source?: string | Uint8Array;
|
|
21
|
+
}>, warnThresholdKb?: number): BundleAssetReport[];
|
|
22
|
+
/**
|
|
23
|
+
* Zero-dependency Vite plugin that logs a sorted raw + gzip bundle breakdown
|
|
24
|
+
* at the end of `vite build` and flags oversized chunks that need lazy splitting.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bundleReport(options?: BundleReportOptions): Plugin;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundle-report/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAMD,8EAA8E;AAC9E,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC,EACrF,eAAe,SAAM,GACpB,iBAAiB,EAAE,CAuBrB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAmBtE"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reads
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* This exists to fix a real gap: a plain `process.env.API_BASE_URL` check
|
|
6
|
-
* (the pattern backon's own generated `generate-client` script uses,
|
|
7
|
-
* correctly, since that script runs under Node/Bun) does nothing useful in
|
|
8
|
-
* a Vite-built browser bundle — `process` isn't defined there, so the
|
|
9
|
-
* check just silently falls through. Vite's own env mechanism is
|
|
10
|
-
* `import.meta.env`, statically replaced at build time, and only
|
|
11
|
-
* `VITE_`-prefixed variables are ever exposed to client code (Vite drops
|
|
12
|
-
* everything else on purpose, so a backend secret sitting in the same
|
|
13
|
-
* .env file never leaks into the browser bundle).
|
|
14
|
-
*
|
|
15
|
-
* Returns "" (relative requests) when unset — correct for same-origin
|
|
16
|
-
* deployment or a dev-server proxy (see backonProxy in the root entry
|
|
17
|
-
* point); set VITE_API_BASE_URL explicitly when the frontend and backend
|
|
18
|
-
* are on different origins.
|
|
2
|
+
* Reads `import.meta.env.VITE_API_BASE_URL` at runtime in a Vite browser
|
|
3
|
+
* bundle, returning `""` when unset (for same-origin deploys or Vite dev proxy).
|
|
19
4
|
*/
|
|
20
5
|
export declare function resolveApiBaseUrl(): string;
|
|
6
|
+
/** Structured error thrown by `createApiClient()` on non-2xx responses, matching backon's error JSON shape. */
|
|
7
|
+
export declare class ApiError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly details?: unknown;
|
|
11
|
+
constructor(status: number, code: string, message: string, details?: unknown);
|
|
12
|
+
}
|
|
13
|
+
export type ApiCredentials = NonNullable<RequestInit["credentials"]>;
|
|
14
|
+
export type ApiBodyInit = NonNullable<RequestInit["body"]>;
|
|
15
|
+
export interface ApiClientOptions {
|
|
16
|
+
/** Override base URL (defaults to `resolveApiBaseUrl() || (DEV ? "/api" : "")`). */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Default fetch credentials mode (defaults to `"same-origin"`). */
|
|
19
|
+
credentials?: ApiCredentials;
|
|
20
|
+
/** Default headers merged into every request. */
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
/** Optional custom fetch implementation (useful for tests or SSR). */
|
|
23
|
+
fetch?: typeof fetch;
|
|
24
|
+
}
|
|
25
|
+
export interface ApiRequestOptions extends Omit<RequestInit, "body"> {
|
|
26
|
+
/** Plain object/array is JSON-stringified automatically; BodyInit values pass through unchanged. */
|
|
27
|
+
body?: unknown;
|
|
28
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lightweight typed fetch wrapper pre-wired for backon backends:
|
|
32
|
+
* resolves `VITE_API_BASE_URL` / dev `/api` proxy, serializes JSON bodies,
|
|
33
|
+
* and unwraps backon `{ error: { code, message, details } }` payloads into `ApiError`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createApiClient(options?: ApiClientOptions): {
|
|
36
|
+
request: <T = unknown>(path: string, init?: ApiRequestOptions) => Promise<T>;
|
|
37
|
+
get: <T = unknown>(path: string, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
38
|
+
post: <T = unknown>(path: string, body?: unknown, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
39
|
+
put: <T = unknown>(path: string, body?: unknown, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
40
|
+
patch: <T = unknown>(path: string, body?: unknown, init?: Omit<ApiRequestOptions, "method" | "body">) => Promise<T>;
|
|
41
|
+
delete: <T = unknown>(path: string, init?: Omit<ApiRequestOptions, "method">) => Promise<T>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Triggers a lazy route/component dynamic import once and caches the trigger
|
|
45
|
+
* so repeated hover/focus events are free. Ideal for declarative React Router links.
|
|
46
|
+
*/
|
|
47
|
+
export declare function preloadChunk(loader: () => Promise<unknown>): void;
|
|
48
|
+
/** Returns React event handlers (`onMouseEnter`, `onFocus`, `onTouchStart`) that preload a lazy chunk on intent. */
|
|
49
|
+
export declare function createPrefetchHandlers(loader: () => Promise<unknown>): {
|
|
50
|
+
onMouseEnter: () => void;
|
|
51
|
+
onFocus: () => void;
|
|
52
|
+
onTouchStart: () => void;
|
|
53
|
+
};
|
|
21
54
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAG1C;AAED,+GAA+G;AAC/G,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAE3B,YAAY,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAM3E;CACF;AAED,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;AACrE,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,sEAAsE;IACtE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;IAClE,oGAAoG;IACpG,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CAC/D;AAmCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB;cAIrC,CAAC,kBAAkB,MAAM,SAAQ,iBAAiB,KAAQ,OAAO,CAAC,CAAC,CAAC;UA2DnF,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;WAE3E,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,OAAO,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;UAE7F,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,OAAO,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;YAE1F,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,OAAO,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC;aAE3F,CAAC,GAAG,OAAO,QAAQ,MAAM,SAAS,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC;EAG/E;AAID;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAOjE;AAED,oHAAoH;AACpH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC;IAGjE,YAAY;IACZ,OAAO;IACP,YAAY;EAEf"}
|
package/dist/client.js
CHANGED
|
@@ -3,6 +3,121 @@ function resolveApiBaseUrl() {
|
|
|
3
3
|
const value = import.meta.env?.VITE_API_BASE_URL;
|
|
4
4
|
return typeof value === "string" && value.length > 0 ? value : "";
|
|
5
5
|
}
|
|
6
|
+
var ApiError = class extends Error {
|
|
7
|
+
status;
|
|
8
|
+
code;
|
|
9
|
+
details;
|
|
10
|
+
constructor(status, code, message, details) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "ApiError";
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.details = details;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function isBodyInit(value) {
|
|
19
|
+
return typeof value === "string" || value instanceof FormData || value instanceof URLSearchParams || value instanceof Blob || value instanceof ArrayBuffer || ArrayBuffer.isView(value) || typeof ReadableStream !== "undefined" && value instanceof ReadableStream;
|
|
20
|
+
}
|
|
21
|
+
function defaultClientBaseUrl() {
|
|
22
|
+
const configured = resolveApiBaseUrl();
|
|
23
|
+
if (configured) return configured;
|
|
24
|
+
return import.meta.env?.DEV ? "/api" : "";
|
|
25
|
+
}
|
|
26
|
+
function buildUrl(baseUrl, path, query) {
|
|
27
|
+
const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
28
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
29
|
+
let url = `${normalizedBase}${normalizedPath}`;
|
|
30
|
+
if (query) {
|
|
31
|
+
const params = new URLSearchParams();
|
|
32
|
+
for (const [k, v] of Object.entries(query)) {
|
|
33
|
+
if (v !== void 0) params.set(k, String(v));
|
|
34
|
+
}
|
|
35
|
+
const qs = params.toString();
|
|
36
|
+
if (qs) url += `${url.includes("?") ? "&" : "?"}${qs}`;
|
|
37
|
+
}
|
|
38
|
+
return url;
|
|
39
|
+
}
|
|
40
|
+
function createApiClient(options = {}) {
|
|
41
|
+
const baseUrl = options.baseUrl ?? defaultClientBaseUrl();
|
|
42
|
+
const fetchFn = options.fetch ?? fetch;
|
|
43
|
+
async function request(path, init = {}) {
|
|
44
|
+
const { body, query, headers, ...rest } = init;
|
|
45
|
+
const mergedHeaders = new Headers(options.headers);
|
|
46
|
+
if (headers) {
|
|
47
|
+
new Headers(headers).forEach((value, key) => mergedHeaders.set(key, value));
|
|
48
|
+
}
|
|
49
|
+
let preparedBody;
|
|
50
|
+
if (body !== void 0) {
|
|
51
|
+
if (isBodyInit(body)) {
|
|
52
|
+
preparedBody = body;
|
|
53
|
+
} else {
|
|
54
|
+
preparedBody = JSON.stringify(body);
|
|
55
|
+
if (!mergedHeaders.has("Content-Type")) {
|
|
56
|
+
mergedHeaders.set("Content-Type", "application/json");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const res = await fetchFn(buildUrl(baseUrl, path, query), {
|
|
61
|
+
credentials: options.credentials ?? "same-origin",
|
|
62
|
+
...rest,
|
|
63
|
+
headers: mergedHeaders,
|
|
64
|
+
body: preparedBody
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
let code = "http_error";
|
|
68
|
+
let message = res.statusText || `Request failed with status ${res.status}`;
|
|
69
|
+
let details;
|
|
70
|
+
const contentType2 = res.headers.get("content-type") ?? "";
|
|
71
|
+
if (contentType2.includes("application/json")) {
|
|
72
|
+
const parsed = await res.json().catch(() => void 0);
|
|
73
|
+
if (parsed?.error) {
|
|
74
|
+
code = parsed.error.code ?? code;
|
|
75
|
+
message = parsed.error.message ?? message;
|
|
76
|
+
details = parsed.error.details;
|
|
77
|
+
} else if (parsed?.message) {
|
|
78
|
+
message = parsed.message;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new ApiError(res.status, code, message, details);
|
|
82
|
+
}
|
|
83
|
+
if (res.status === 204 || res.headers.get("content-length") === "0") {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
87
|
+
if (contentType.includes("application/json")) {
|
|
88
|
+
return await res.json();
|
|
89
|
+
}
|
|
90
|
+
return await res.text();
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
request,
|
|
94
|
+
get: (path, init) => request(path, { ...init, method: "GET" }),
|
|
95
|
+
post: (path, body, init) => request(path, { ...init, method: "POST", body }),
|
|
96
|
+
put: (path, body, init) => request(path, { ...init, method: "PUT", body }),
|
|
97
|
+
patch: (path, body, init) => request(path, { ...init, method: "PATCH", body }),
|
|
98
|
+
delete: (path, init) => request(path, { ...init, method: "DELETE" })
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
var preloadedLoaders = /* @__PURE__ */ new WeakSet();
|
|
102
|
+
function preloadChunk(loader) {
|
|
103
|
+
if (preloadedLoaders.has(loader)) return;
|
|
104
|
+
preloadedLoaders.add(loader);
|
|
105
|
+
void loader().catch(() => {
|
|
106
|
+
preloadedLoaders.delete(loader);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function createPrefetchHandlers(loader) {
|
|
110
|
+
const trigger = () => preloadChunk(loader);
|
|
111
|
+
return {
|
|
112
|
+
onMouseEnter: trigger,
|
|
113
|
+
onFocus: trigger,
|
|
114
|
+
onTouchStart: trigger
|
|
115
|
+
};
|
|
116
|
+
}
|
|
6
117
|
export {
|
|
118
|
+
ApiError,
|
|
119
|
+
createApiClient,
|
|
120
|
+
createPrefetchHandlers,
|
|
121
|
+
preloadChunk,
|
|
7
122
|
resolveApiBaseUrl
|
|
8
123
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { frontonCompression } from "./compression/index";
|
|
|
4
4
|
export type { FrontonCompressionOptions } from "./compression/index";
|
|
5
5
|
export { backonProxy } from "./backon/index";
|
|
6
6
|
export type { BackonProxyOptions } from "./backon/index";
|
|
7
|
+
export { bundleReport } from "./bundle-report/index";
|
|
8
|
+
export type { BundleReportOptions, BundleAssetReport } from "./bundle-report/index";
|
|
7
9
|
export { compressImages } from "./media/images";
|
|
8
10
|
export type { CompressImagesOptions } from "./media/images";
|
|
9
11
|
export { compressVideos } from "./media/videos";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAOpF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -224,6 +224,47 @@ function backonProxy(target, options = {}) {
|
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
// src/bundle-report/index.ts
|
|
228
|
+
import { gzipSync } from "node:zlib";
|
|
229
|
+
function formatKb(bytes) {
|
|
230
|
+
return `${(bytes / 1024).toFixed(2)} kB`;
|
|
231
|
+
}
|
|
232
|
+
function summarizeBundleAssets(bundle, warnThresholdKb = 250) {
|
|
233
|
+
const thresholdBytes = warnThresholdKb * 1024;
|
|
234
|
+
const reports = [];
|
|
235
|
+
for (const [fileName, item] of Object.entries(bundle)) {
|
|
236
|
+
if (!/\.(?:m?js|css)$/.test(fileName)) continue;
|
|
237
|
+
const raw = item.type === "chunk" ? Buffer.from(item.code ?? "", "utf-8") : typeof item.source === "string" ? Buffer.from(item.source, "utf-8") : Buffer.from(item.source ?? new Uint8Array());
|
|
238
|
+
const gzipBytes = gzipSync(raw).length;
|
|
239
|
+
reports.push({
|
|
240
|
+
fileName,
|
|
241
|
+
rawBytes: raw.length,
|
|
242
|
+
gzipBytes,
|
|
243
|
+
oversized: raw.length > thresholdBytes
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
reports.sort((a, b) => b.rawBytes - a.rawBytes);
|
|
247
|
+
return reports;
|
|
248
|
+
}
|
|
249
|
+
function bundleReport(options = {}) {
|
|
250
|
+
const warnThresholdKb = options.warnThresholdKb ?? 250;
|
|
251
|
+
return {
|
|
252
|
+
name: "fronton:bundle-report",
|
|
253
|
+
apply: "build",
|
|
254
|
+
generateBundle(_outputOptions, bundle) {
|
|
255
|
+
const entries = summarizeBundleAssets(bundle, warnThresholdKb);
|
|
256
|
+
options.onReport?.(entries);
|
|
257
|
+
if (options.silent || entries.length === 0) return;
|
|
258
|
+
console.log("\n[fronton] Bundle report:");
|
|
259
|
+
for (const entry of entries) {
|
|
260
|
+
const flag = entry.oversized ? ` [> ${warnThresholdKb} kB \u2014 consider lazy()]` : "";
|
|
261
|
+
console.log(` ${entry.fileName.padEnd(38)} ${formatKb(entry.rawBytes).padStart(10)} (gzip ${formatKb(entry.gzipBytes)})${flag}`);
|
|
262
|
+
}
|
|
263
|
+
console.log();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
227
268
|
// src/media/images.ts
|
|
228
269
|
import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
229
270
|
import { resolve } from "node:path";
|
|
@@ -458,6 +499,7 @@ function compressVideos(options = {}) {
|
|
|
458
499
|
}
|
|
459
500
|
export {
|
|
460
501
|
backonProxy,
|
|
502
|
+
bundleReport,
|
|
461
503
|
compressImages,
|
|
462
504
|
compressVideos,
|
|
463
505
|
frontonCompression,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mednours/fronton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Opinionated runtime pieces for fronton-scaffolded Vite projects — Tailwind class obfuscation, gzip/brotli compression, and backon API wiring.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"sharp": "^0.35.0",
|
|
45
45
|
"fluent-ffmpeg": "^2.1.3",
|
|
46
46
|
"ffmpeg-static": "^5.3.0",
|
|
47
|
-
"motion": "^12.0.0"
|
|
47
|
+
"motion": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"sharp": {
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"magic-string": "^1.
|
|
65
|
-
"postcss": "^8.5.
|
|
64
|
+
"magic-string": "^1.4.5",
|
|
65
|
+
"postcss": "^8.5.34",
|
|
66
66
|
"postcss-selector-parser": "^7.1.5",
|
|
67
|
-
"vite-plugin-compression2": "^2.5.
|
|
67
|
+
"vite-plugin-compression2": "^2.5.4"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/bun": "latest",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"esbuild": "^0.28.2",
|
|
73
73
|
"ffmpeg-static": "^5.3.0",
|
|
74
74
|
"fluent-ffmpeg": "^2.1.3",
|
|
75
|
-
"motion": "^
|
|
76
|
-
"react": "^19.
|
|
77
|
-
"sharp": "^0.35.
|
|
75
|
+
"motion": "^15.0.1",
|
|
76
|
+
"react": "^19.3.1",
|
|
77
|
+
"sharp": "^0.35.6",
|
|
78
78
|
"typescript": "^7.0.2",
|
|
79
|
-
"vite": "^8.
|
|
79
|
+
"vite": "^8.4.1"
|
|
80
80
|
}
|
|
81
81
|
}
|