vike-solid 0.0.0 → 0.0.6

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/cli/entry.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import("../dist/index.js");
package/client.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // For tsconfig.json#compilerOptions.types
2
+ import "vite/client";
@@ -0,0 +1,36 @@
1
+ import { createComponent } from 'solid-js/web';
2
+ import { createContext, useContext } from 'solid-js';
3
+
4
+ function getGlobalObject(
5
+ // We use the filename as key; each `getGlobalObject()` call should live in a unique filename.
6
+ key, defaultValue) {
7
+ const allGlobalObjects = globalThis.__vite_plugin_ssr = globalThis.__vite_plugin_ssr || {};
8
+ const globalObject = allGlobalObjects[key] = allGlobalObjects[key] || defaultValue;
9
+ return globalObject;
10
+ }
11
+
12
+ const {
13
+ Context
14
+ } = getGlobalObject("PageContextProvider.ts", {
15
+ Context: createContext()
16
+ });
17
+ function PageContextProvider(props) {
18
+ if (!props.pageContext) throw new Error("Argument pageContext missing");
19
+ return createComponent(Context.Provider, {
20
+ get value() {
21
+ return props.pageContext;
22
+ },
23
+ get children() {
24
+ return props.children;
25
+ }
26
+ });
27
+ }
28
+
29
+ /** Access the pageContext from any SolidJS component */
30
+ function usePageContext() {
31
+ const pageContext = useContext(Context);
32
+ if (!pageContext) throw new Error("<PageContextProvider> is needed for being able to use usePageContext()");
33
+ return pageContext;
34
+ }
35
+
36
+ export { PageContextProvider as P, usePageContext as u };
@@ -0,0 +1,19 @@
1
+ import { Config } from 'vite-plugin-ssr/types';
2
+ import { Component } from 'solid-js';
3
+
4
+ type UserConfig = Partial<VikeSolidConfig & {
5
+ Page: Component;
6
+ } & Pick<Config, "route" | "prerender" | "iKnowThePerformanceRisksOfAsyncRouteFunctions">>;
7
+ type VikeSolidConfig = {
8
+ /** Solid element renderer and appended into &lt;head>&lt;/head> */
9
+ Head: Component;
10
+ Layout: Component;
11
+ title: string;
12
+ description: string;
13
+ /**
14
+ * @default 'en'
15
+ */
16
+ lang: string;
17
+ };
18
+
19
+ export { UserConfig as U, VikeSolidConfig as V };
@@ -0,0 +1,23 @@
1
+ var _config = {
2
+ clientRouting: true,
3
+ hydrationCanBeAborted: true,
4
+ meta: {
5
+ Head: {
6
+ env: "server-only"
7
+ },
8
+ Layout: {
9
+ env: "server-and-client"
10
+ },
11
+ title: {
12
+ env: "server-and-client"
13
+ },
14
+ description: {
15
+ env: "server-only"
16
+ },
17
+ lang: {
18
+ env: "server-only"
19
+ }
20
+ }
21
+ };
22
+
23
+ export { _config as default };
@@ -0,0 +1,112 @@
1
+ import { createComponent, Dynamic, mergeProps, memo, hydrate, render } from 'solid-js/web';
2
+ import { P as PageContextProvider, u as usePageContext } from './PageContextProvider-a90cda5a.js';
3
+ import { createStore, reconcile } from 'solid-js/store';
4
+ import 'solid-js';
5
+
6
+ function getTitle(pageContext) {
7
+ if (typeof pageContext.title === "string") {
8
+ return pageContext.title;
9
+ }
10
+ if (pageContext.title) {
11
+ throw new Error("pageContext.title should be a string");
12
+ }
13
+ const {
14
+ title
15
+ } = pageContext.config;
16
+ if (typeof title === "string") {
17
+ return title;
18
+ }
19
+ if (!title) {
20
+ return null;
21
+ }
22
+ const {
23
+ configDefinedAt
24
+ } = pageContext.configEntries.title[0];
25
+ if (typeof title === "function") {
26
+ const val = title(pageContext);
27
+ if (typeof val === "string") {
28
+ return val;
29
+ }
30
+ if (val) {
31
+ throw new Error(configDefinedAt + " should return a string");
32
+ }
33
+ }
34
+ throw new Error(configDefinedAt + " should be a string or a function returning a string");
35
+ }
36
+
37
+ function getPageElement(pageContext) {
38
+ const page = createComponent(PageContextProvider, {
39
+ pageContext: pageContext,
40
+ get children() {
41
+ return createComponent(Wrapper, {
42
+ get children() {
43
+ return createComponent(Layout, {
44
+ get children() {
45
+ return createComponent(Page, {});
46
+ }
47
+ });
48
+ }
49
+ });
50
+ }
51
+ });
52
+ return page;
53
+ }
54
+ function Wrapper(props) {
55
+ const pageContext = usePageContext();
56
+ return createComponent(Dynamic, {
57
+ get component() {
58
+ return pageContext.config.Wrapper ?? Passthrough;
59
+ },
60
+ get children() {
61
+ return props.children;
62
+ }
63
+ });
64
+ }
65
+ function Layout(props) {
66
+ const pageContext = usePageContext();
67
+ return createComponent(Dynamic, {
68
+ get component() {
69
+ return pageContext.config.Layout ?? Passthrough;
70
+ },
71
+ get children() {
72
+ return props.children;
73
+ }
74
+ });
75
+ }
76
+ function Page() {
77
+ const pageContext = usePageContext();
78
+ return createComponent(Dynamic, mergeProps({
79
+ get component() {
80
+ return pageContext.Page;
81
+ }
82
+ }, () => pageContext.pageProps ?? {}));
83
+ }
84
+ function Passthrough(props) {
85
+ return memo(() => props.children);
86
+ }
87
+
88
+ const [pageContextStore, setPageContext] = createStore({});
89
+ let dispose;
90
+ let rendered = false;
91
+ async function onRenderClient(pageContext) {
92
+ if (!rendered) {
93
+ // Dispose to prevent duplicate pages when navigating.
94
+ if (dispose) dispose();
95
+ setPageContext(pageContext);
96
+ const container = document.getElementById("page-view");
97
+ if (pageContext.isHydration) {
98
+ dispose = hydrate(() => getPageElement(pageContextStore), container);
99
+ } else {
100
+ dispose = render(() => getPageElement(pageContextStore), container);
101
+ }
102
+ rendered = true;
103
+ } else {
104
+ setPageContext(reconcile(pageContext));
105
+ }
106
+ const title = getTitle(pageContext);
107
+ if (title !== null) {
108
+ document.title = title;
109
+ }
110
+ }
111
+
112
+ export { onRenderClient as default };
@@ -0,0 +1,126 @@
1
+ import { createComponent, Dynamic, mergeProps, renderToString, renderToStream, generateHydrationScript } from 'solid-js/web';
2
+ import { escapeInject, stampPipe, dangerouslySkipEscape } from 'vite-plugin-ssr/server';
3
+ import { P as PageContextProvider, u as usePageContext } from './PageContextProvider-a90cda5a.js';
4
+ import 'solid-js';
5
+
6
+ function getTitle(pageContext) {
7
+ if (typeof pageContext.title === "string") {
8
+ return pageContext.title;
9
+ }
10
+ if (pageContext.title) {
11
+ throw new Error("pageContext.title should be a string");
12
+ }
13
+ const {
14
+ title
15
+ } = pageContext.config;
16
+ if (typeof title === "string") {
17
+ return title;
18
+ }
19
+ if (!title) {
20
+ return null;
21
+ }
22
+ const {
23
+ configDefinedAt
24
+ } = pageContext.configEntries.title[0];
25
+ if (typeof title === "function") {
26
+ const val = title(pageContext);
27
+ if (typeof val === "string") {
28
+ return val;
29
+ }
30
+ if (val) {
31
+ throw new Error(configDefinedAt + " should return a string");
32
+ }
33
+ }
34
+ throw new Error(configDefinedAt + " should be a string or a function returning a string");
35
+ }
36
+
37
+ function getPageElement(pageContext) {
38
+ const page = createComponent(PageContextProvider, {
39
+ pageContext: pageContext,
40
+ get children() {
41
+ return createComponent(Wrapper, {
42
+ get children() {
43
+ return createComponent(Layout, {
44
+ get children() {
45
+ return createComponent(Page, {});
46
+ }
47
+ });
48
+ }
49
+ });
50
+ }
51
+ });
52
+ return page;
53
+ }
54
+ function Wrapper(props) {
55
+ const pageContext = usePageContext();
56
+ return createComponent(Dynamic, {
57
+ get component() {
58
+ return pageContext.config.Wrapper ?? Passthrough;
59
+ },
60
+ get children() {
61
+ return props.children;
62
+ }
63
+ });
64
+ }
65
+ function Layout(props) {
66
+ const pageContext = usePageContext();
67
+ return createComponent(Dynamic, {
68
+ get component() {
69
+ return pageContext.config.Layout ?? Passthrough;
70
+ },
71
+ get children() {
72
+ return props.children;
73
+ }
74
+ });
75
+ }
76
+ function Page() {
77
+ const pageContext = usePageContext();
78
+ return createComponent(Dynamic, mergeProps({
79
+ get component() {
80
+ return pageContext.Page;
81
+ }
82
+ }, () => pageContext.pageProps ?? {}));
83
+ }
84
+ function Passthrough(props) {
85
+ return props.children;
86
+ }
87
+
88
+ async function onRenderHtml(pageContext) {
89
+ const title = getTitle(pageContext);
90
+ const titleTag = !title ? "" : escapeInject`<title>${title}</title>`;
91
+ const {
92
+ description
93
+ } = pageContext.config;
94
+ const descriptionTag = !description ? "" : escapeInject`<meta name="description" content="${description}" />`;
95
+ const Head = pageContext.config.Head || (() => []);
96
+ const headHtml = renderToString(() => createComponent(PageContextProvider, {
97
+ pageContext: pageContext,
98
+ get children() {
99
+ return createComponent(Head, {});
100
+ }
101
+ }));
102
+ const {
103
+ pipe
104
+ } = renderToStream(() => getPageElement(pageContext));
105
+ // const asString = renderToString(() => page);
106
+ stampPipe(pipe, "node-stream");
107
+ const lang = pageContext.config.lang || "en";
108
+ const documentHtml = escapeInject`<!DOCTYPE html>
109
+ <html lang='${lang}'>
110
+ <head>
111
+ <meta charset="UTF-8" />
112
+ ${titleTag}
113
+ ${descriptionTag}
114
+ ${dangerouslySkipEscape(headHtml)}
115
+ ${dangerouslySkipEscape(generateHydrationScript())}
116
+ </head>
117
+ <body>
118
+ <div id="page-view">${pipe}</div>
119
+ </body>
120
+ </html>`;
121
+ return {
122
+ documentHtml
123
+ };
124
+ }
125
+
126
+ export { onRenderHtml as default };
@@ -0,0 +1,3 @@
1
+ var _passToClient = ["pageProps", "title"];
2
+
3
+ export { _passToClient as default };
@@ -0,0 +1,18 @@
1
+ import { build } from 'vite';
2
+ import { c as config } from './vite.config-8c4f846f.js';
3
+ import 'vite-plugin-solid';
4
+ import 'vite-plugin-ssr/plugin';
5
+
6
+ // import { prerender } from 'vite-plugin-ssr/prerender'
7
+
8
+ main();
9
+ async function main() {
10
+ await build(config);
11
+ await build({
12
+ ...config,
13
+ build: {
14
+ ssr: true
15
+ }
16
+ });
17
+ // await prerender({ viteConfig: config as any })
18
+ }
@@ -0,0 +1,27 @@
1
+ import { PageContextBuiltIn, PageContextBuiltInClientWithClientRouting } from 'vite-plugin-ssr/types';
2
+ import { V as VikeSolidConfig } from '../_config-4f584ee9.js';
3
+ import { JSX } from 'solid-js';
4
+
5
+ type Page = (pageProps: PageProps) => JSX.Element;
6
+ type PageProps = Record<string, unknown>;
7
+ type WrapperComponent = ({ children }: {
8
+ children: any;
9
+ }) => JSX.Element;
10
+ type PageContextCommon = {
11
+ Page: Page;
12
+ pageProps?: PageProps;
13
+ config: {
14
+ Layout?: WrapperComponent;
15
+ Wrapper?: WrapperComponent;
16
+ };
17
+ };
18
+ type PageContextServer = PageContextBuiltIn<Page> & PageContextCommon & {
19
+ config: Partial<VikeSolidConfig>;
20
+ };
21
+ type PageContextClient = PageContextBuiltInClientWithClientRouting<Page> & PageContextCommon;
22
+ type PageContext = PageContextClient | PageContextServer;
23
+
24
+ /** Access the pageContext from any SolidJS component */
25
+ declare function usePageContext(): PageContext;
26
+
27
+ export { usePageContext };
@@ -0,0 +1,11 @@
1
+ import { createServer } from 'vite';
2
+ import { c as config } from './vite.config-8c4f846f.js';
3
+ import 'vite-plugin-solid';
4
+ import 'vite-plugin-ssr/plugin';
5
+
6
+ main();
7
+ async function main() {
8
+ const server = await createServer(config);
9
+ await server.listen();
10
+ server.printUrls();
11
+ }
@@ -0,0 +1,3 @@
1
+ export { PageContextBuiltIn } from 'vite-plugin-ssr/types';
2
+ export { U as Config } from './_config-4f584ee9.js';
3
+ import 'solid-js';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ Error.stackTraceLimit = Infinity;
2
+ const cmd = parseCliArgs();
3
+ cli();
4
+ async function cli() {
5
+ if (cmd === "dev") {
6
+ await import('./dev-9481c139.js');
7
+ }
8
+ if (cmd === "build") {
9
+ await import('./build-f275ba07.js');
10
+ }
11
+ if (cmd === "preview") {
12
+ await import('./preview-07e97d22.js');
13
+ }
14
+ }
15
+ function parseCliArgs() {
16
+ const args = process.argv.filter(Boolean).slice(2);
17
+ let cmd;
18
+ const isDev = args.includes("dev");
19
+ const isPreview = args.includes("preview");
20
+ const isBuild = args.includes("build");
21
+ if (isDev) {
22
+ cmd = "dev";
23
+ } else if (isBuild) {
24
+ cmd = "build";
25
+ } else if (isPreview) {
26
+ cmd = "preview";
27
+ } else {
28
+ throw new Error(`DocPress: unknown command \`$ docpress ${args.join(" ")}\`. Known commands: \`$ docpress dev\` and \`$ docpress preview\`.`);
29
+ }
30
+ return cmd;
31
+ }
package/dist/index2.js ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,10 @@
1
+ import { preview } from 'vite';
2
+ import { c as config } from './vite.config-8c4f846f.js';
3
+ import 'vite-plugin-solid';
4
+ import 'vite-plugin-ssr/plugin';
5
+
6
+ main();
7
+ async function main() {
8
+ const server = await preview(config);
9
+ server.printUrls();
10
+ }
@@ -0,0 +1,3 @@
1
+ export { u as usePageContext } from './PageContextProvider-a90cda5a.js';
2
+ import 'solid-js/web';
3
+ import 'solid-js';
@@ -0,0 +1,9 @@
1
+ import { Options as Options$1 } from 'vite-plugin-solid';
2
+ import { Plugin } from 'vite';
3
+
4
+ interface Options {
5
+ solid?: Options$1;
6
+ }
7
+ declare function export_default(options?: Options): Plugin[];
8
+
9
+ export { Options, export_default as default };
@@ -0,0 +1,36 @@
1
+ import solidPlugin from 'vite-plugin-solid';
2
+ import ssr from 'vite-plugin-ssr/plugin';
3
+ import { mergeConfig } from 'vite';
4
+
5
+ function overrideConfig() {
6
+ return {
7
+ name: "vite-plugin-vike-solid",
8
+ config: () => ({
9
+ optimizeDeps: {
10
+ include: ["solid-js"]
11
+ },
12
+ ssr: {
13
+ external: ["vike-solid", "vite-plugin-ssr/server"]
14
+ }
15
+ })
16
+ };
17
+ }
18
+ function vitePluginVikeSolid (options = {}) {
19
+ return [solidPlugin(mergeConfig({
20
+ ssr: true,
21
+ typescript: {
22
+ onlyRemoveTypeImports: true
23
+ },
24
+ solid: {
25
+ hydratable: true
26
+ }
27
+ }, options.solid ?? {})), ssr({
28
+ extensions: [{
29
+ npmPackageName: "vike-solid",
30
+ pageConfigsDistFiles: ["vike-solid/renderer/+onRenderHtml.js", "vike-solid/renderer/+onRenderClient.js", "vike-solid/renderer/+config.js", "vike-solid/renderer/+passToClient.js"]
31
+ }],
32
+ disableAutoFullBuild: true
33
+ }), overrideConfig()];
34
+ }
35
+
36
+ export { vitePluginVikeSolid as default };
@@ -0,0 +1,45 @@
1
+ import solidPlugin from 'vite-plugin-solid';
2
+ import ssr from 'vite-plugin-ssr/plugin';
3
+ import { mergeConfig } from 'vite';
4
+
5
+ function overrideConfig() {
6
+ return {
7
+ name: "vite-plugin-vike-solid",
8
+ config: () => ({
9
+ optimizeDeps: {
10
+ include: ["solid-js"]
11
+ },
12
+ ssr: {
13
+ external: ["vike-solid", "vite-plugin-ssr/server"]
14
+ }
15
+ })
16
+ };
17
+ }
18
+ function vpvs (options = {}) {
19
+ return [solidPlugin(mergeConfig({
20
+ ssr: true,
21
+ typescript: {
22
+ onlyRemoveTypeImports: true
23
+ },
24
+ solid: {
25
+ hydratable: true
26
+ }
27
+ }, options.solid ?? {})), ssr({
28
+ extensions: [{
29
+ npmPackageName: "vike-solid",
30
+ pageConfigsDistFiles: ["vike-solid/renderer/+onRenderHtml.js", "vike-solid/renderer/+onRenderClient.js", "vike-solid/renderer/+config.js", "vike-solid/renderer/+passToClient.js"]
31
+ }],
32
+ disableAutoFullBuild: true
33
+ }), overrideConfig()];
34
+ }
35
+
36
+ const root = process.cwd();
37
+ const config = {
38
+ root,
39
+ plugins: [vpvs()],
40
+ server: {
41
+ port: process.env.PORT ? parseInt(process.env.PORT) : undefined
42
+ }
43
+ };
44
+
45
+ export { config as c };
package/package.json CHANGED
@@ -1,4 +1,65 @@
1
1
  {
2
2
  "name": "vike-solid",
3
- "version": "0.0.0"
4
- }
3
+ "version": "0.0.6",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./dist/index2.js",
7
+ "./vite": "./dist/vite-plugin-vike-solid.js",
8
+ "./usePageContext": "./dist/usePageContext.js",
9
+ "./renderer/+onRenderHtml.js": "./dist/_onRenderHtml.js",
10
+ "./renderer/+onRenderClient.js": "./dist/_onRenderClient.js",
11
+ "./renderer/+config.js": "./dist/_config.js",
12
+ "./renderer/+passToClient.js": "./dist/_passToClient.js"
13
+ },
14
+ "dependencies": {
15
+ "vite": "^4.3.5",
16
+ "vite-plugin-solid": "^2.7.0",
17
+ "vite-plugin-ssr": "^0.4.123"
18
+ },
19
+ "peerDependencies": {
20
+ "solid-js": "^1.7.1"
21
+ },
22
+ "devDependencies": {
23
+ "@babel/core": "^7.21.8",
24
+ "@babel/preset-env": "^7.21.5",
25
+ "@babel/preset-typescript": "^7.21.5",
26
+ "@rollup/plugin-babel": "^6.0.3",
27
+ "@rollup/plugin-node-resolve": "^15.0.2",
28
+ "@types/node": "^18.16.6",
29
+ "babel-preset-solid": "^1.7.4",
30
+ "bumpp": "^9.1.0",
31
+ "rollup": "3.20.4",
32
+ "rollup-plugin-dts": "^5.3.0",
33
+ "solid-js": "^1.7.5",
34
+ "tslib": "^2.5.0",
35
+ "typescript": "^5.0.4"
36
+ },
37
+ "typesVersions": {
38
+ "*": {
39
+ ".": [
40
+ "dist/index.d.ts"
41
+ ],
42
+ "vite": [
43
+ "dist/vite-plugin-vike-solid.d.ts"
44
+ ],
45
+ "client": [
46
+ "client.d.ts"
47
+ ],
48
+ "usePageContext": [
49
+ "./dist/components/usePageContext.d.ts"
50
+ ]
51
+ }
52
+ },
53
+ "files": [
54
+ "dist/",
55
+ "client.d.ts"
56
+ ],
57
+ "bin": "./cli/entry.js",
58
+ "repository": "github:magne4000/vike-solid",
59
+ "license": "MIT",
60
+ "scripts": {
61
+ "dev": "rollup -c rollup.config.js --watch",
62
+ "build": "rollup -c rollup.config.js",
63
+ "release": "pnpm run build && bumpp --commit --push --tag && pnpm publish"
64
+ }
65
+ }
package/readme.md DELETED
@@ -1,3 +0,0 @@
1
- This is work in progress, stay tuned...
2
-
3
- If I didn't publish anything in a while and you want this package, then reach out and I'll give it away.