webstudio 0.0.0-4f7bf18
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/LICENSE +661 -0
- package/README.md +145 -0
- package/bin.js +5 -0
- package/lib/cli.js +6606 -0
- package/package.json +88 -0
- package/templates/cloudflare/WS_CF_README.md +48 -0
- package/templates/cloudflare/functions/[[path]].ts +9 -0
- package/templates/cloudflare/load-context.ts +9 -0
- package/templates/cloudflare/package.json +22 -0
- package/templates/cloudflare/tsconfig.json +18 -0
- package/templates/cloudflare/vite.config.ts +21 -0
- package/templates/cloudflare/worker-configuration.d.ts +3 -0
- package/templates/cloudflare/wrangler.toml +55 -0
- package/templates/defaults/app/constants.mjs +12 -0
- package/templates/defaults/app/extension.ts +16 -0
- package/templates/defaults/app/root.tsx +35 -0
- package/templates/defaults/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/defaults/app/route-templates/html.tsx +297 -0
- package/templates/defaults/app/route-templates/redirect.tsx +6 -0
- package/templates/defaults/app/route-templates/xml.tsx +85 -0
- package/templates/defaults/app/routes/[robots.txt].tsx +24 -0
- package/templates/defaults/package.json +35 -0
- package/templates/defaults/public/favicon.ico +0 -0
- package/templates/defaults/tsconfig.json +22 -0
- package/templates/defaults/vite.config.ts +16 -0
- package/templates/internal/package.json +11 -0
- package/templates/internal/tsconfig.json +5 -0
- package/templates/netlify-edge-functions/app/constants.mjs +29 -0
- package/templates/netlify-edge-functions/app/entry.server.tsx +21 -0
- package/templates/netlify-edge-functions/netlify.toml +16 -0
- package/templates/netlify-edge-functions/package.json +9 -0
- package/templates/netlify-edge-functions/vite.config.ts +18 -0
- package/templates/netlify-functions/app/constants.mjs +29 -0
- package/templates/netlify-functions/app/entry.server.tsx +1 -0
- package/templates/netlify-functions/netlify.toml +16 -0
- package/templates/netlify-functions/package.json +9 -0
- package/templates/netlify-functions/vite.config.ts +18 -0
- package/templates/react-router-docker/.dockerignore +4 -0
- package/templates/react-router-docker/Dockerfile +24 -0
- package/templates/react-router-docker/app/constants.mjs +18 -0
- package/templates/react-router-docker/app/extension.ts +13 -0
- package/templates/react-router-docker/app/root.tsx +35 -0
- package/templates/react-router-docker/app/route-templates/default-sitemap.tsx +34 -0
- package/templates/react-router-docker/app/route-templates/html.tsx +295 -0
- package/templates/react-router-docker/app/route-templates/redirect.tsx +6 -0
- package/templates/react-router-docker/app/route-templates/xml.tsx +85 -0
- package/templates/react-router-docker/app/routes/[_image].$.ts +24 -0
- package/templates/react-router-docker/app/routes/[robots.txt].tsx +24 -0
- package/templates/react-router-docker/app/routes.ts +4 -0
- package/templates/react-router-docker/package.json +39 -0
- package/templates/react-router-docker/public/favicon.ico +0 -0
- package/templates/react-router-docker/tsconfig.json +18 -0
- package/templates/react-router-docker/vite.config.ts +6 -0
- package/templates/saas-helpers/package.json +6 -0
- package/templates/saas-helpers/tsconfig.json +18 -0
- package/templates/ssg/app/constants.mjs +13 -0
- package/templates/ssg/app/route-templates/html/+Head.tsx +92 -0
- package/templates/ssg/app/route-templates/html/+Page.tsx +21 -0
- package/templates/ssg/app/route-templates/html/+data.ts +37 -0
- package/templates/ssg/package.json +31 -0
- package/templates/ssg/pages/+config.ts +12 -0
- package/templates/ssg/public/favicon.ico +0 -0
- package/templates/ssg/renderer/+onRenderClient.tsx +30 -0
- package/templates/ssg/renderer/+onRenderHtml.tsx +29 -0
- package/templates/ssg/tsconfig.json +22 -0
- package/templates/ssg/vike.d.ts +25 -0
- package/templates/ssg/vite.config.ts +7 -0
- package/templates/ssg-netlify/app/constants.mjs +30 -0
- package/templates/ssg-vercel/app/constants.mjs +26 -0
- package/templates/ssg-vercel/public/vercel.json +11 -0
- package/templates/vercel/.vercelignore +8 -0
- package/templates/vercel/app/constants.mjs +25 -0
- package/templates/vercel/package.json +1 -0
- package/templates/vercel/vercel.json +11 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PageContextServer } from "vike/types";
|
|
2
|
+
import { redirect } from "vike/abort";
|
|
3
|
+
import { loadResources } from "@webstudio-is/sdk/runtime";
|
|
4
|
+
import { getPageMeta, getResources } from "__SERVER__";
|
|
5
|
+
|
|
6
|
+
export const data = async (pageContext: PageContextServer) => {
|
|
7
|
+
const url = new URL(pageContext.urlOriginal, "http://url");
|
|
8
|
+
const headers = new Headers(pageContext.headers ?? {});
|
|
9
|
+
const host = headers.get("x-forwarded-host") || headers.get("host") || "";
|
|
10
|
+
url.host = host;
|
|
11
|
+
url.protocol = "https";
|
|
12
|
+
|
|
13
|
+
const params = pageContext.routeParams;
|
|
14
|
+
const system = {
|
|
15
|
+
params,
|
|
16
|
+
search: Object.fromEntries(url.searchParams),
|
|
17
|
+
origin: url.origin,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const resources = await loadResources(fetch, getResources({ system }).data);
|
|
21
|
+
const pageMeta = getPageMeta({ system, resources });
|
|
22
|
+
|
|
23
|
+
if (pageMeta.redirect) {
|
|
24
|
+
const status =
|
|
25
|
+
pageMeta.status === 301 || pageMeta.status === 302
|
|
26
|
+
? pageMeta.status
|
|
27
|
+
: 302;
|
|
28
|
+
throw redirect(pageMeta.redirect, status);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
url: url.href,
|
|
33
|
+
system,
|
|
34
|
+
resources,
|
|
35
|
+
pageMeta,
|
|
36
|
+
} satisfies PageContextServer["data"];
|
|
37
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"private": true,
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "vite build",
|
|
7
|
+
"dev": "vite dev",
|
|
8
|
+
"typecheck": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@webstudio-is/image": "0.0.0-4f7bf18",
|
|
12
|
+
"@webstudio-is/react-sdk": "0.0.0-4f7bf18",
|
|
13
|
+
"@webstudio-is/sdk": "0.0.0-4f7bf18",
|
|
14
|
+
"@webstudio-is/sdk-components-react": "0.0.0-4f7bf18",
|
|
15
|
+
"@webstudio-is/sdk-components-animation": "0.0.0-4f7bf18",
|
|
16
|
+
"@webstudio-is/sdk-components-react-radix": "0.0.0-4f7bf18",
|
|
17
|
+
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
18
|
+
"react-dom": "18.3.0-canary-14898b6a9-20240318",
|
|
19
|
+
"vike": "^0.4.218"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "^18.2.70",
|
|
23
|
+
"@types/react-dom": "^18.2.25",
|
|
24
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
25
|
+
"typescript": "5.7.3",
|
|
26
|
+
"vite": "^5.4.11"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Root, createRoot } from "react-dom/client";
|
|
2
|
+
import type { OnRenderClientSync } from "vike/types";
|
|
3
|
+
// @todo think about how to make __generated__ typeable
|
|
4
|
+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { CustomCode } from "../app/__generated__/_index";
|
|
7
|
+
|
|
8
|
+
let root: Root;
|
|
9
|
+
|
|
10
|
+
export const onRenderClient: OnRenderClientSync = (pageContext) => {
|
|
11
|
+
const lang = pageContext.data.pageMeta.language || "en";
|
|
12
|
+
const Head = pageContext.config.Head ?? (() => <></>);
|
|
13
|
+
const Page = pageContext.Page ?? (() => <></>);
|
|
14
|
+
const htmlContent = (
|
|
15
|
+
<>
|
|
16
|
+
<head>
|
|
17
|
+
<meta charSet="UTF-8" />
|
|
18
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
19
|
+
<Head data={pageContext.data} />
|
|
20
|
+
<CustomCode />
|
|
21
|
+
</head>
|
|
22
|
+
<Page data={pageContext.data} />
|
|
23
|
+
</>
|
|
24
|
+
);
|
|
25
|
+
if (root === undefined) {
|
|
26
|
+
root = createRoot(document.documentElement);
|
|
27
|
+
}
|
|
28
|
+
document.documentElement.lang = lang;
|
|
29
|
+
root.render(htmlContent);
|
|
30
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { renderToString } from "react-dom/server";
|
|
2
|
+
import { dangerouslySkipEscape, escapeInject } from "vike/server";
|
|
3
|
+
import type { OnRenderHtmlSync } from "vike/types";
|
|
4
|
+
// @todo think about how to make __generated__ typeable
|
|
5
|
+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { CustomCode } from "../app/__generated__/_index";
|
|
8
|
+
|
|
9
|
+
export const onRenderHtml: OnRenderHtmlSync = (pageContext) => {
|
|
10
|
+
const lang = pageContext.data.pageMeta.language || "en";
|
|
11
|
+
const Head = pageContext.config.Head ?? (() => <></>);
|
|
12
|
+
const Page = pageContext.Page ?? (() => <></>);
|
|
13
|
+
const html = dangerouslySkipEscape(
|
|
14
|
+
renderToString(
|
|
15
|
+
<html lang={lang}>
|
|
16
|
+
<head>
|
|
17
|
+
<meta charSet="UTF-8" />
|
|
18
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
19
|
+
<Head data={pageContext.data} />
|
|
20
|
+
<CustomCode />
|
|
21
|
+
</head>
|
|
22
|
+
<Page data={pageContext.data} />
|
|
23
|
+
</html>
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
return escapeInject`<!DOCTYPE html>
|
|
27
|
+
${html}
|
|
28
|
+
`;
|
|
29
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["**/*.ts", "**/*.tsx", "**/*.mjs"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
5
|
+
"types": [
|
|
6
|
+
"vite/client",
|
|
7
|
+
"@webstudio-is/react-sdk/placeholder",
|
|
8
|
+
"./vike.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"module": "ESNext",
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"target": "ES2022",
|
|
16
|
+
"strict": true,
|
|
17
|
+
"allowJs": true,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
"skipLibCheck": true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ImageLoader } from "@webstudio-is/image";
|
|
2
|
+
import type { PageMeta, System } from "@webstudio-is/sdk";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
namespace Vike {
|
|
6
|
+
interface Config {
|
|
7
|
+
lang?: (props: { data: PageData }) => string;
|
|
8
|
+
Head?: (props: { data: PageData }) => React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface PageContext {
|
|
12
|
+
constants: {
|
|
13
|
+
assetBaseUrl: string;
|
|
14
|
+
imageLoader: ImageLoader;
|
|
15
|
+
};
|
|
16
|
+
data: {
|
|
17
|
+
url: string;
|
|
18
|
+
system: System;
|
|
19
|
+
resources: Record<string, unknown>;
|
|
20
|
+
pageMeta: PageMeta;
|
|
21
|
+
};
|
|
22
|
+
Page?: (props: { data: PageData }) => React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const assetBaseUrl = "/assets/";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
10
|
+
*/
|
|
11
|
+
export const imageLoader = (props) => {
|
|
12
|
+
if (process.env.NODE_ENV !== "production") {
|
|
13
|
+
return props.src;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (props.format === "raw") {
|
|
17
|
+
return props.src;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// https://docs.netlify.com/image-cdn/overview/
|
|
21
|
+
const searchParams = new URLSearchParams();
|
|
22
|
+
searchParams.set("url", props.src);
|
|
23
|
+
searchParams.set("w", props.width.toString());
|
|
24
|
+
if (props.height) {
|
|
25
|
+
searchParams.set("h", props.height.toString());
|
|
26
|
+
}
|
|
27
|
+
searchParams.set("q", props.quality.toString());
|
|
28
|
+
// fit=contain by default
|
|
29
|
+
return `/.netlify/images?${searchParams}`;
|
|
30
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const assetBaseUrl = "/assets/";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
10
|
+
*/
|
|
11
|
+
export const imageLoader = (props) => {
|
|
12
|
+
if (process.env.NODE_ENV !== "production") {
|
|
13
|
+
return props.src;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (props.format === "raw") {
|
|
17
|
+
return props.src;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
|
|
21
|
+
const searchParams = new URLSearchParams();
|
|
22
|
+
searchParams.set("url", props.src);
|
|
23
|
+
searchParams.set("w", props.width.toString());
|
|
24
|
+
searchParams.set("q", props.quality.toString());
|
|
25
|
+
return `/_vercel/image?${searchParams}`;
|
|
26
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use mjs extension as constants in this file is shared with the build script
|
|
3
|
+
* and we use `node --eval` to extract the constants.
|
|
4
|
+
*/
|
|
5
|
+
export const assetBaseUrl = "/assets/";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {import("@webstudio-is/image").ImageLoader}
|
|
9
|
+
*/
|
|
10
|
+
export const imageLoader = (props) => {
|
|
11
|
+
if (process.env.NODE_ENV !== "production") {
|
|
12
|
+
return props.src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (props.format === "raw") {
|
|
16
|
+
return props.src;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
|
|
20
|
+
const searchParams = new URLSearchParams();
|
|
21
|
+
searchParams.set("url", props.src);
|
|
22
|
+
searchParams.set("w", props.width.toString());
|
|
23
|
+
searchParams.set("q", props.quality.toString());
|
|
24
|
+
return `/_vercel/image?${searchParams}`;
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|