@jxsuite/compiler 0.5.4 → 0.6.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/compiler.js +106 -89
- package/package.json +4 -3
- package/src/compiler.js +9 -2
- package/src/shared.js +6 -1
- package/src/site/image-cache.js +106 -0
- package/src/site/image-optimizer.js +187 -0
- package/src/site/image-transform.js +149 -0
- package/src/site/site-build.js +84 -14
- package/src/site/site-loader.js +10 -0
- package/src/targets/compile-client.js +1 -1
- package/src/targets/compile-server.js +48 -9
package/src/site/site-loader.js
CHANGED
|
@@ -27,10 +27,19 @@ const DEFAULTS = {
|
|
|
27
27
|
state: {},
|
|
28
28
|
collections: {},
|
|
29
29
|
redirects: {},
|
|
30
|
+
images: {
|
|
31
|
+
optimize: true,
|
|
32
|
+
widths: [320, 640, 960, 1280, 1920],
|
|
33
|
+
formats: ["webp", "avif"],
|
|
34
|
+
quality: { webp: 80, avif: 65, jpeg: 80, png: 80 },
|
|
35
|
+
sizes: "(max-width: 768px) 100vw, 50vw",
|
|
36
|
+
lazyLoad: true,
|
|
37
|
+
},
|
|
30
38
|
build: {
|
|
31
39
|
outDir: "./dist",
|
|
32
40
|
format: "directory",
|
|
33
41
|
trailingSlash: "always",
|
|
42
|
+
provider: null,
|
|
34
43
|
},
|
|
35
44
|
};
|
|
36
45
|
|
|
@@ -65,6 +74,7 @@ export function loadProjectConfig(projectRoot) {
|
|
|
65
74
|
...DEFAULTS,
|
|
66
75
|
...raw,
|
|
67
76
|
defaults: { ...DEFAULTS.defaults, ...raw.defaults },
|
|
77
|
+
images: { ...DEFAULTS.images, ...raw.images },
|
|
68
78
|
build: { ...DEFAULTS.build, ...raw.build },
|
|
69
79
|
};
|
|
70
80
|
|
|
@@ -32,15 +32,7 @@ export async function compileServer(sourcePath, opts = {}) {
|
|
|
32
32
|
.map(({ exportName, src }) => `import { ${exportName} } from '${src}'`)
|
|
33
33
|
.join("\n");
|
|
34
34
|
|
|
35
|
-
const routes = entries
|
|
36
|
-
.map(
|
|
37
|
-
({ exportName }) => `
|
|
38
|
-
app.post('${baseUrl}/${exportName}', async (c) => {
|
|
39
|
-
const args = await c.req.json().catch(() => ({}))
|
|
40
|
-
return c.json(await ${exportName}(args))
|
|
41
|
-
})`,
|
|
42
|
-
)
|
|
43
|
-
.join("\n");
|
|
35
|
+
const routes = entries.map(({ exportName }) => buildRoute(exportName, baseUrl)).join("\n");
|
|
44
36
|
|
|
45
37
|
return `// Generated by @jxsuite/compiler — do not edit manually
|
|
46
38
|
// Deploy as a Cloudflare Worker, Node server, or Bun process.
|
|
@@ -55,3 +47,50 @@ ${routes}
|
|
|
55
47
|
export default app
|
|
56
48
|
`;
|
|
57
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generate a bundled Hono server entry from pre-collected server entries across an entire site.
|
|
53
|
+
* Used when `build.provider` is set in project.json. Returns null if no entries are provided.
|
|
54
|
+
*
|
|
55
|
+
* @param {{ exportName: string; src: string }[]} entries - Resolved server entries
|
|
56
|
+
* @param {object} [opts]
|
|
57
|
+
* @param {string} [opts.baseUrl] - Base path for server endpoints. Default is `'/_jx/server'`
|
|
58
|
+
* @param {string | null} [opts.provider] - Deployment provider: `"cloudflare"`, `"node"`, `"bun"`
|
|
59
|
+
* @returns {string | null} Complete worker/server source string, or null
|
|
60
|
+
*/
|
|
61
|
+
export function compileSiteServer(entries, opts = {}) {
|
|
62
|
+
const { baseUrl = "/_jx/server", provider = null } = opts;
|
|
63
|
+
if (entries.length === 0) return null;
|
|
64
|
+
|
|
65
|
+
const imports = entries
|
|
66
|
+
.map(({ exportName, src }) => `import { ${exportName} } from '${src}'`)
|
|
67
|
+
.join("\n");
|
|
68
|
+
|
|
69
|
+
const routes = entries.map(({ exportName }) => buildRoute(exportName, baseUrl)).join("\n");
|
|
70
|
+
|
|
71
|
+
const providerBlock =
|
|
72
|
+
provider === "cloudflare" ? "\napp.all('*', (c) => c.env.ASSETS.fetch(c.req.raw))\n" : "\n";
|
|
73
|
+
|
|
74
|
+
return `// Generated by @jxsuite/compiler — do not edit manually
|
|
75
|
+
import { Hono } from 'hono'
|
|
76
|
+
${imports}
|
|
77
|
+
|
|
78
|
+
const app = new Hono()
|
|
79
|
+
${routes}
|
|
80
|
+
${providerBlock}
|
|
81
|
+
export default app
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @param {string} exportName @param {string} baseUrl */
|
|
86
|
+
function buildRoute(exportName, baseUrl) {
|
|
87
|
+
return `
|
|
88
|
+
app.post('${baseUrl}/${exportName}', async (c) => {
|
|
89
|
+
const args = await c.req.json().catch(() => ({}))
|
|
90
|
+
try {
|
|
91
|
+
return c.json(await ${exportName}(args, c.env))
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return c.json({ ok: false, error: e?.message ?? 'Server error' }, 500)
|
|
94
|
+
}
|
|
95
|
+
})`;
|
|
96
|
+
}
|