Skip to content

Commit cbdc510

Browse files
committed
feat: split server and client exports
1 parent 937b127 commit cbdc510

File tree

14 files changed

+135
-44
lines changed

14 files changed

+135
-44
lines changed

examples/basic/src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link } from "pranx";
1+
import { Link } from "pranx/client";
22

33
export function Header() {
44
return (
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import "github-markdown-css";
2-
import { mount, StartApp } from "pranx";
1+
import { mount, StartApp } from "pranx/client";
32
import "./styles/styles.css";
43

5-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
6-
mount(<StartApp />, document.querySelector("#app")!);
4+
mount(<StartApp />, document.body);

examples/basic/src/entry-server.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Meta, Scripts, type ServerEntryProps } from "pranx";
1+
import { type ServerEntryProps } from "pranx";
2+
import { Meta, Scripts } from "pranx/server";
23

34
export default function ServerEntry({ children }: ServerEntryProps) {
45
return (
@@ -34,7 +35,7 @@ export default function ServerEntry({ children }: ServerEntryProps) {
3435
<Meta />
3536
</head>
3637
<body>
37-
<div id="app">{children}</div>
38+
{children}
3839
<Scripts />
3940
</body>
4041
</html>

examples/basic/src/pages/products/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { useAppContext, type GetServerSidePropsFunction } from "pranx";
1+
import { type GetServerSidePropsFunction } from "pranx";
2+
import { useAppContext } from "pranx/client";
23
import { Header } from "src/components/Header";
34
import "./products.css";
45

56
export default function ProductsPage(props: { cuantity: number }) {
67
const { props_status } = useAppContext();
78
console.log(props_status);
9+
810
return (
911
<div>
1012
<Header />

packages/pranx/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test": "vitest run",
1111
"check": "tsc --noEmit -p ./tsconfig.json",
1212
"style": "bun run format && bun run lint",
13-
"format": "prettier --write --cache src scripts",
13+
"format": "prettier --write --cache src scripts types",
1414
"lint": "biome lint . --fix --unsafe",
1515
"prepublishOnly": "bun run build:prod",
1616
"release": "pnpm run build:prod && changelogen --release --prerelease --publish -publishTag beta && git push --follow-tags"
@@ -29,6 +29,14 @@
2929
"import": "./dist/index.js",
3030
"types": "./types/index.d.ts"
3131
},
32+
"./client": {
33+
"import": "./dist/client/index.js",
34+
"types": "./types/client.d.ts"
35+
},
36+
"./server": {
37+
"import": "./dist/server/index.js",
38+
"types": "./types/server.d.ts"
39+
},
3240
"./package.json": "./package.json"
3341
},
3442
"files": [

packages/pranx/scripts/build.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const OUTPUT_DIR = join(process.cwd(), "dist");
77

88
await fse.emptyDir(OUTPUT_DIR);
99

10+
// Bin output
1011
await esbuild.build({
1112
entryPoints: [join(SOURCE_DIR, "bin", "index.ts"), join(SOURCE_DIR, "index.ts")],
1213
bundle: true,
@@ -47,3 +48,85 @@ await esbuild.build({
4748
".json": "json",
4849
},
4950
});
51+
52+
// Client output
53+
await esbuild.build({
54+
entryPoints: [join(SOURCE_DIR, "client", "public-exports.ts")],
55+
bundle: true,
56+
outfile: join(OUTPUT_DIR, "client", "index.js"),
57+
target: "ESNext",
58+
format: "esm",
59+
60+
keepNames: true,
61+
minify: true,
62+
metafile: false,
63+
64+
chunkNames: "_chunks/[name]-[hash]",
65+
assetNames: "_assets/[name]-[hash]",
66+
67+
mainFields: ["module", "main"], // Prefer ESM versions
68+
conditions: ["import", "module", "require"], // Module resolution conditions
69+
70+
treeShaking: true,
71+
packages: "external",
72+
73+
jsx: "automatic",
74+
jsxImportSource: "preact",
75+
76+
platform: "node",
77+
78+
alias: {
79+
"@": SOURCE_DIR,
80+
"react": "preact/compat",
81+
"react-dom": "preact/compat",
82+
},
83+
84+
loader: {
85+
".js": "jsx",
86+
".jsx": "jsx",
87+
".ts": "tsx",
88+
".tsx": "tsx",
89+
".json": "json",
90+
},
91+
});
92+
93+
// Server output
94+
await esbuild.build({
95+
entryPoints: [join(SOURCE_DIR, "server", "public-exports.ts")],
96+
bundle: true,
97+
outfile: join(OUTPUT_DIR, "server", "index.js"),
98+
target: "ESNext",
99+
format: "esm",
100+
101+
keepNames: true,
102+
minify: true,
103+
metafile: false,
104+
105+
chunkNames: "_chunks/[name]-[hash]",
106+
assetNames: "_assets/[name]-[hash]",
107+
108+
mainFields: ["module", "main"], // Prefer ESM versions
109+
conditions: ["import", "module", "require"], // Module resolution conditions
110+
111+
treeShaking: true,
112+
packages: "external",
113+
114+
jsx: "automatic",
115+
jsxImportSource: "preact",
116+
117+
platform: "node",
118+
119+
alias: {
120+
"@": SOURCE_DIR,
121+
"react": "preact/compat",
122+
"react-dom": "preact/compat",
123+
},
124+
125+
loader: {
126+
".js": "jsx",
127+
".jsx": "jsx",
128+
".ts": "tsx",
129+
".tsx": "tsx",
130+
".json": "json",
131+
},
132+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { useAppContext } from "./app-context.js";
2+
export { Link } from "./components/link.js";
3+
export { mount } from "./mount.js";
4+
export { StartApp } from "./start-app.js";

packages/pranx/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
// Client
2-
export { useAppContext } from "./client/app-context.js";
3-
export { Link } from "./client/components/link.js";
4-
export { mount } from "./client/mount.js";
5-
export { StartApp } from "./client/start-app.js";
6-
7-
// Server
8-
export { Meta } from "./server/Meta.js";
9-
export { Scripts } from "./server/Scripts.js";
1+
export type {};

packages/pranx/src/server/Meta.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const META_TAG = `__PRANX_METADATA__-${Math.random()}`;
1+
export const META_TAG = "__PRANX_METADATA__";
22

33
export function Meta() {
44
return META_TAG;

packages/pranx/src/server/Scripts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const SCRIPTS_TAG = `__PRANX_SCRIPTS__-${Math.random()}`;
1+
export const SCRIPTS_TAG = "__PRANX_SCRIPTS__";
22

33
export function Scripts() {
44
return SCRIPTS_TAG;

0 commit comments

Comments
 (0)