meno-core 1.0.12 → 1.0.14
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/build-static.ts
CHANGED
|
@@ -32,6 +32,34 @@ function hashContent(content: string): string {
|
|
|
32
32
|
return createHash('sha256').update(content).digest('hex').slice(0, 8);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Minify JavaScript code using Bun's built-in bundler
|
|
37
|
+
*/
|
|
38
|
+
async function minifyJS(code: string): Promise<string> {
|
|
39
|
+
const tempFile = join('/tmp', `meno-minify-${Date.now()}.js`);
|
|
40
|
+
try {
|
|
41
|
+
await writeFile(tempFile, code, 'utf-8');
|
|
42
|
+
|
|
43
|
+
const result = await Bun.build({
|
|
44
|
+
entrypoints: [tempFile],
|
|
45
|
+
minify: true,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (result.success && result.outputs.length > 0) {
|
|
49
|
+
return await result.outputs[0].text();
|
|
50
|
+
}
|
|
51
|
+
// Fallback to original if minification fails
|
|
52
|
+
return code;
|
|
53
|
+
} finally {
|
|
54
|
+
// Clean up temp file
|
|
55
|
+
try {
|
|
56
|
+
rmSync(tempFile, { force: true });
|
|
57
|
+
} catch {
|
|
58
|
+
// Ignore cleanup errors
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
35
63
|
/**
|
|
36
64
|
* Track JavaScript files to avoid duplicates
|
|
37
65
|
* Maps content hash -> script path
|
|
@@ -43,7 +71,9 @@ const jsFileCache = new Map<string, string>();
|
|
|
43
71
|
* Returns the path to reference in HTML
|
|
44
72
|
*/
|
|
45
73
|
async function getScriptPath(jsContent: string, distDir: string): Promise<string> {
|
|
46
|
-
|
|
74
|
+
// Minify JavaScript for production
|
|
75
|
+
const minified = await minifyJS(jsContent);
|
|
76
|
+
const hash = hashContent(minified);
|
|
47
77
|
|
|
48
78
|
// Check if we already wrote this content
|
|
49
79
|
if (jsFileCache.has(hash)) {
|
|
@@ -56,10 +86,10 @@ async function getScriptPath(jsContent: string, distDir: string): Promise<string
|
|
|
56
86
|
mkdirSync(scriptsDir, { recursive: true });
|
|
57
87
|
}
|
|
58
88
|
|
|
59
|
-
// Write script file
|
|
89
|
+
// Write minified script file
|
|
60
90
|
const scriptPath = `/_scripts/${hash}.js`;
|
|
61
91
|
const fullPath = join(distDir, '_scripts', `${hash}.js`);
|
|
62
|
-
await writeFile(fullPath,
|
|
92
|
+
await writeFile(fullPath, minified, 'utf-8');
|
|
63
93
|
|
|
64
94
|
// Cache for reuse
|
|
65
95
|
jsFileCache.set(hash, scriptPath);
|
|
@@ -235,12 +235,17 @@ export async function generateSSRHTML(
|
|
|
235
235
|
: '';
|
|
236
236
|
const iconTags = [faviconTag, appleTouchIconTag].filter(Boolean).join('\n ');
|
|
237
237
|
|
|
238
|
+
// Script preload tag - eliminates critical request chain by discovering script early
|
|
239
|
+
const scriptPreloadTag = extScriptPath
|
|
240
|
+
? `<link rel="preload" href="${extScriptPath}" as="script">`
|
|
241
|
+
: '';
|
|
242
|
+
|
|
238
243
|
const htmlDocument = `<!DOCTYPE html>
|
|
239
244
|
<html lang="${rendered.locale}" theme="${themeConfig.default}">
|
|
240
245
|
<head>
|
|
241
246
|
<meta charset="UTF-8">
|
|
242
247
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
243
|
-
${iconTags ? iconTags + '\n ' : ''}${fontPreloadTags ? fontPreloadTags + '\n ' : ''}${rendered.meta}
|
|
248
|
+
${iconTags ? iconTags + '\n ' : ''}${scriptPreloadTag ? scriptPreloadTag + '\n ' : ''}${fontPreloadTags ? fontPreloadTags + '\n ' : ''}${rendered.meta}
|
|
244
249
|
${configInlineScript}${cmsInlineScript}<style>
|
|
245
250
|
${fontCSS ? fontCSS + '\n ' : ''}${themeColorVariablesCSS ? themeColorVariablesCSS + '\n ' : ''}* {
|
|
246
251
|
margin: 0;
|
|
@@ -28,9 +28,9 @@ export interface ImageMetadata {
|
|
|
28
28
|
export type ImageMetadataMap = Map<string, ImageMetadata>;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Responsive image widths for variant detection
|
|
31
|
+
* Responsive image widths for variant detection (optimized for mobile 2x/3x DPR and desktop)
|
|
32
32
|
*/
|
|
33
|
-
export const RESPONSIVE_WIDTHS = [500,
|
|
33
|
+
export const RESPONSIVE_WIDTHS = [500, 800, 1080, 1600, 2400] as const;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Default sizes attribute for responsive images
|