@nestjs-ssr/react 0.2.5 → 0.3.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/README.md +7 -7
- package/dist/cli/init.js +35 -72
- package/dist/cli/init.mjs +35 -72
- package/dist/client.d.mts +55 -304
- package/dist/client.d.ts +55 -304
- package/dist/client.js +360 -13
- package/dist/client.mjs +336 -5
- package/dist/{index-BMdluY1g.d.mts → index-BzOLOiIZ.d.ts} +207 -44
- package/dist/{index-rl0S5kqW.d.ts → index-DdE--mA2.d.mts} +207 -44
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +646 -317
- package/dist/index.mjs +640 -319
- package/dist/render/index.d.mts +2 -2
- package/dist/render/index.d.ts +2 -2
- package/dist/render/index.js +610 -315
- package/dist/render/index.mjs +610 -315
- package/dist/{render-response.interface-Dc-Kwb09.d.mts → render-response.interface-CxbuKGnV.d.mts} +57 -1
- package/dist/{render-response.interface-Dc-Kwb09.d.ts → render-response.interface-CxbuKGnV.d.ts} +57 -1
- package/dist/templates/entry-client.tsx +21 -5
- package/dist/templates/entry-server.tsx +28 -6
- package/dist/use-page-context-05ODF4zW.d.ts +281 -0
- package/dist/use-page-context-CGT9woWe.d.mts +281 -0
- package/package.json +1 -1
- package/src/global.d.ts +11 -0
- package/src/templates/entry-client.tsx +21 -5
- package/src/templates/entry-server.tsx +28 -6
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
React as a view layer for NestJS. Controllers return data. Components render it. One app.
|
|
7
7
|
|
|
8
|
-
**[Documentation](https://georgialexandrov.github.io/
|
|
8
|
+
**[Documentation](https://georgialexandrov.github.io/nestjs-ssr/)** | **[Getting Started](https://georgialexandrov.github.io/nestjs-ssr/guide/installation)**
|
|
9
9
|
|
|
10
10
|
## Quick Start
|
|
11
11
|
|
|
@@ -70,13 +70,13 @@ render(<ProductDetail data={{ product: mockProduct }} />);
|
|
|
70
70
|
|
|
71
71
|
## Documentation
|
|
72
72
|
|
|
73
|
-
**[georgialexandrov.github.io/
|
|
73
|
+
**[georgialexandrov.github.io/nestjs-ssr](https://georgialexandrov.github.io/nestjs-ssr/)**
|
|
74
74
|
|
|
75
|
-
- [Installation](https://georgialexandrov.github.io/
|
|
76
|
-
- [Rendering](https://georgialexandrov.github.io/
|
|
77
|
-
- [Request Context](https://georgialexandrov.github.io/
|
|
78
|
-
- [Configuration](https://georgialexandrov.github.io/
|
|
79
|
-
- [API Reference](https://georgialexandrov.github.io/
|
|
75
|
+
- [Installation](https://georgialexandrov.github.io/nestjs-ssr/guide/installation)
|
|
76
|
+
- [Rendering](https://georgialexandrov.github.io/nestjs-ssr/guide/rendering)
|
|
77
|
+
- [Request Context](https://georgialexandrov.github.io/nestjs-ssr/guide/request-context)
|
|
78
|
+
- [Configuration](https://georgialexandrov.github.io/nestjs-ssr/guide/configuration)
|
|
79
|
+
- [API Reference](https://georgialexandrov.github.io/nestjs-ssr/guide/api)
|
|
80
80
|
|
|
81
81
|
## Contributing
|
|
82
82
|
|
package/dist/cli/init.js
CHANGED
|
@@ -33,14 +33,16 @@ var main = citty.defineCommand({
|
|
|
33
33
|
description: "Skip automatic dependency installation",
|
|
34
34
|
default: false
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
port: {
|
|
37
37
|
type: "string",
|
|
38
|
-
description:
|
|
38
|
+
description: "Vite dev server port",
|
|
39
|
+
default: "5173"
|
|
39
40
|
}
|
|
40
41
|
},
|
|
41
42
|
async run({ args }) {
|
|
42
43
|
const cwd = process.cwd();
|
|
43
44
|
const viewsDir = args.views;
|
|
45
|
+
const vitePort = parseInt(args.port, 10) || 5173;
|
|
44
46
|
const packageJsonPath = path.join(cwd, "package.json");
|
|
45
47
|
const tsconfigPath = path.join(cwd, "tsconfig.json");
|
|
46
48
|
consola.consola.box("@nestjs-ssr/react initialization");
|
|
@@ -80,32 +82,6 @@ var main = citty.defineCommand({
|
|
|
80
82
|
consola.consola.error("Failed to validate package.json:", error);
|
|
81
83
|
process.exit(1);
|
|
82
84
|
}
|
|
83
|
-
let integrationType = args.integration;
|
|
84
|
-
if (!integrationType) {
|
|
85
|
-
const response = await consola.consola.prompt("How do you want to run Vite during development?", {
|
|
86
|
-
type: "select",
|
|
87
|
-
options: [
|
|
88
|
-
{
|
|
89
|
-
label: "Separate server (Vite runs on its own port, e.g., 5173)",
|
|
90
|
-
value: "separate"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
label: "Integrated with NestJS (Vite middleware runs within NestJS)",
|
|
94
|
-
value: "integrated"
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
});
|
|
98
|
-
integrationType = response;
|
|
99
|
-
}
|
|
100
|
-
if (![
|
|
101
|
-
"separate",
|
|
102
|
-
"integrated"
|
|
103
|
-
].includes(integrationType)) {
|
|
104
|
-
consola.consola.error(`Invalid integration type: "${integrationType}". Must be "separate" or "integrated"`);
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
consola.consola.info(`Using ${integrationType === "separate" ? "separate server" : "integrated"} mode
|
|
108
|
-
`);
|
|
109
85
|
const templateLocations = [
|
|
110
86
|
path.resolve(__dirname$1, "../../src/templates"),
|
|
111
87
|
path.resolve(__dirname$1, "../templates")
|
|
@@ -159,28 +135,17 @@ var main = citty.defineCommand({
|
|
|
159
135
|
consola.consola.warn("vite.config already exists");
|
|
160
136
|
consola.consola.info("Please manually add to your Vite config:");
|
|
161
137
|
consola.consola.log(" import { resolve } from 'path';");
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
consola.consola.log(" },");
|
|
168
|
-
}
|
|
138
|
+
consola.consola.log(" server: {");
|
|
139
|
+
consola.consola.log(` port: ${vitePort},`);
|
|
140
|
+
consola.consola.log(" strictPort: true,");
|
|
141
|
+
consola.consola.log(` hmr: { port: ${vitePort} },`);
|
|
142
|
+
consola.consola.log(" },");
|
|
169
143
|
consola.consola.log(" build: {");
|
|
170
144
|
consola.consola.log(" rollupOptions: {");
|
|
171
145
|
consola.consola.log(` input: { client: resolve(process.cwd(), '${viewsDir}/entry-client.tsx') }`);
|
|
172
146
|
consola.consola.log(" }");
|
|
173
147
|
consola.consola.log(" }");
|
|
174
148
|
} else {
|
|
175
|
-
const serverConfig = integrationType === "separate" ? ` server: {
|
|
176
|
-
port: 5173,
|
|
177
|
-
strictPort: true,
|
|
178
|
-
hmr: { port: 5173 },
|
|
179
|
-
},
|
|
180
|
-
` : ` server: {
|
|
181
|
-
middlewareMode: true,
|
|
182
|
-
},
|
|
183
|
-
`;
|
|
184
149
|
const viteConfig = `import { defineConfig } from 'vite';
|
|
185
150
|
import react from '@vitejs/plugin-react';
|
|
186
151
|
import { resolve } from 'path';
|
|
@@ -192,7 +157,12 @@ export default defineConfig({
|
|
|
192
157
|
'@': resolve(process.cwd(), 'src'),
|
|
193
158
|
},
|
|
194
159
|
},
|
|
195
|
-
|
|
160
|
+
server: {
|
|
161
|
+
port: ${vitePort},
|
|
162
|
+
strictPort: true,
|
|
163
|
+
hmr: { port: ${vitePort} },
|
|
164
|
+
},
|
|
165
|
+
build: {
|
|
196
166
|
outDir: 'dist/client',
|
|
197
167
|
manifest: true,
|
|
198
168
|
rollupOptions: {
|
|
@@ -393,7 +363,7 @@ ${serverConfig}build: {
|
|
|
393
363
|
const importsMatch = appModule.match(importsPattern);
|
|
394
364
|
if (importsMatch) {
|
|
395
365
|
const existingImports = importsMatch[2].trim();
|
|
396
|
-
const renderModuleConfig =
|
|
366
|
+
const renderModuleConfig = vitePort === 5173 ? "RenderModule.forRoot()" : `RenderModule.forRoot({ vite: { port: ${vitePort} } })`;
|
|
397
367
|
if (existingImports === "") {
|
|
398
368
|
appModule = appModule.replace(importsPattern, `$1${renderModuleConfig}`);
|
|
399
369
|
} else {
|
|
@@ -437,15 +407,15 @@ ${serverConfig}build: {
|
|
|
437
407
|
packageJson.scripts["build:server"] = `vite build --ssr ${viewsDir}/entry-server.tsx --outDir dist/server`;
|
|
438
408
|
shouldUpdate = true;
|
|
439
409
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
410
|
+
if (!packageJson.scripts["dev:vite"]) {
|
|
411
|
+
packageJson.scripts["dev:vite"] = `vite --port ${vitePort}`;
|
|
412
|
+
shouldUpdate = true;
|
|
413
|
+
}
|
|
414
|
+
if (!packageJson.scripts["dev:nest"]) {
|
|
415
|
+
packageJson.scripts["dev:nest"] = "nest start --watch --watchAssets --preserveWatchOutput";
|
|
416
|
+
shouldUpdate = true;
|
|
417
|
+
}
|
|
418
|
+
if (!packageJson.scripts["start:dev"] || !packageJson.scripts["start:dev"].includes("concurrently")) {
|
|
449
419
|
packageJson.scripts["start:dev"] = 'concurrently --raw -n vite,nest -c cyan,green "pnpm:dev:vite" "pnpm:dev:nest"';
|
|
450
420
|
shouldUpdate = true;
|
|
451
421
|
}
|
|
@@ -478,16 +448,14 @@ ${serverConfig}build: {
|
|
|
478
448
|
react: "^19.0.0",
|
|
479
449
|
"react-dom": "^19.0.0",
|
|
480
450
|
vite: "^7.0.0",
|
|
481
|
-
"@vitejs/plugin-react": "^4.0.0"
|
|
451
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
452
|
+
"http-proxy-middleware": "^3.0.0"
|
|
482
453
|
};
|
|
483
454
|
const requiredDevDeps = {
|
|
484
455
|
"@types/react": "^19.0.0",
|
|
485
|
-
"@types/react-dom": "^19.0.0"
|
|
456
|
+
"@types/react-dom": "^19.0.0",
|
|
457
|
+
concurrently: "^9.0.0"
|
|
486
458
|
};
|
|
487
|
-
if (integrationType === "separate") {
|
|
488
|
-
requiredDeps["http-proxy-middleware"] = "^3.0.0";
|
|
489
|
-
requiredDevDeps["concurrently"] = "^9.0.0";
|
|
490
|
-
}
|
|
491
459
|
const missingDeps = [];
|
|
492
460
|
const missingDevDeps = [];
|
|
493
461
|
const allDeps = {
|
|
@@ -552,17 +520,12 @@ ${serverConfig}build: {
|
|
|
552
520
|
consola.consola.log(" @Get()");
|
|
553
521
|
consola.consola.log(" @Render(Home)");
|
|
554
522
|
consola.consola.log(' home() { return { message: "Hello" }; }');
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
consola.consola.log(" Terminal 2: pnpm dev:nest");
|
|
562
|
-
} else {
|
|
563
|
-
consola.consola.info("\n3. Start the dev server: pnpm start:dev");
|
|
564
|
-
consola.consola.info(" (Vite middleware will be integrated into NestJS)");
|
|
565
|
-
}
|
|
523
|
+
consola.consola.info("\n3. Start development with HMR:");
|
|
524
|
+
consola.consola.log(" pnpm start:dev");
|
|
525
|
+
consola.consola.info(` This runs both Vite (port ${vitePort}) and NestJS concurrently`);
|
|
526
|
+
consola.consola.info("\n Or run them separately:");
|
|
527
|
+
consola.consola.log(" Terminal 1: pnpm dev:vite");
|
|
528
|
+
consola.consola.log(" Terminal 2: pnpm dev:nest");
|
|
566
529
|
}
|
|
567
530
|
});
|
|
568
531
|
citty.runMain(main);
|
package/dist/cli/init.mjs
CHANGED
|
@@ -30,14 +30,16 @@ var main = defineCommand({
|
|
|
30
30
|
description: "Skip automatic dependency installation",
|
|
31
31
|
default: false
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
port: {
|
|
34
34
|
type: "string",
|
|
35
|
-
description:
|
|
35
|
+
description: "Vite dev server port",
|
|
36
|
+
default: "5173"
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
39
|
async run({ args }) {
|
|
39
40
|
const cwd = process.cwd();
|
|
40
41
|
const viewsDir = args.views;
|
|
42
|
+
const vitePort = parseInt(args.port, 10) || 5173;
|
|
41
43
|
const packageJsonPath = join(cwd, "package.json");
|
|
42
44
|
const tsconfigPath = join(cwd, "tsconfig.json");
|
|
43
45
|
consola.box("@nestjs-ssr/react initialization");
|
|
@@ -77,32 +79,6 @@ var main = defineCommand({
|
|
|
77
79
|
consola.error("Failed to validate package.json:", error);
|
|
78
80
|
process.exit(1);
|
|
79
81
|
}
|
|
80
|
-
let integrationType = args.integration;
|
|
81
|
-
if (!integrationType) {
|
|
82
|
-
const response = await consola.prompt("How do you want to run Vite during development?", {
|
|
83
|
-
type: "select",
|
|
84
|
-
options: [
|
|
85
|
-
{
|
|
86
|
-
label: "Separate server (Vite runs on its own port, e.g., 5173)",
|
|
87
|
-
value: "separate"
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
label: "Integrated with NestJS (Vite middleware runs within NestJS)",
|
|
91
|
-
value: "integrated"
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
});
|
|
95
|
-
integrationType = response;
|
|
96
|
-
}
|
|
97
|
-
if (![
|
|
98
|
-
"separate",
|
|
99
|
-
"integrated"
|
|
100
|
-
].includes(integrationType)) {
|
|
101
|
-
consola.error(`Invalid integration type: "${integrationType}". Must be "separate" or "integrated"`);
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
consola.info(`Using ${integrationType === "separate" ? "separate server" : "integrated"} mode
|
|
105
|
-
`);
|
|
106
82
|
const templateLocations = [
|
|
107
83
|
resolve(__dirname$1, "../../src/templates"),
|
|
108
84
|
resolve(__dirname$1, "../templates")
|
|
@@ -156,28 +132,17 @@ var main = defineCommand({
|
|
|
156
132
|
consola.warn("vite.config already exists");
|
|
157
133
|
consola.info("Please manually add to your Vite config:");
|
|
158
134
|
consola.log(" import { resolve } from 'path';");
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
consola.log(" },");
|
|
165
|
-
}
|
|
135
|
+
consola.log(" server: {");
|
|
136
|
+
consola.log(` port: ${vitePort},`);
|
|
137
|
+
consola.log(" strictPort: true,");
|
|
138
|
+
consola.log(` hmr: { port: ${vitePort} },`);
|
|
139
|
+
consola.log(" },");
|
|
166
140
|
consola.log(" build: {");
|
|
167
141
|
consola.log(" rollupOptions: {");
|
|
168
142
|
consola.log(` input: { client: resolve(process.cwd(), '${viewsDir}/entry-client.tsx') }`);
|
|
169
143
|
consola.log(" }");
|
|
170
144
|
consola.log(" }");
|
|
171
145
|
} else {
|
|
172
|
-
const serverConfig = integrationType === "separate" ? ` server: {
|
|
173
|
-
port: 5173,
|
|
174
|
-
strictPort: true,
|
|
175
|
-
hmr: { port: 5173 },
|
|
176
|
-
},
|
|
177
|
-
` : ` server: {
|
|
178
|
-
middlewareMode: true,
|
|
179
|
-
},
|
|
180
|
-
`;
|
|
181
146
|
const viteConfig = `import { defineConfig } from 'vite';
|
|
182
147
|
import react from '@vitejs/plugin-react';
|
|
183
148
|
import { resolve } from 'path';
|
|
@@ -189,7 +154,12 @@ export default defineConfig({
|
|
|
189
154
|
'@': resolve(process.cwd(), 'src'),
|
|
190
155
|
},
|
|
191
156
|
},
|
|
192
|
-
|
|
157
|
+
server: {
|
|
158
|
+
port: ${vitePort},
|
|
159
|
+
strictPort: true,
|
|
160
|
+
hmr: { port: ${vitePort} },
|
|
161
|
+
},
|
|
162
|
+
build: {
|
|
193
163
|
outDir: 'dist/client',
|
|
194
164
|
manifest: true,
|
|
195
165
|
rollupOptions: {
|
|
@@ -390,7 +360,7 @@ ${serverConfig}build: {
|
|
|
390
360
|
const importsMatch = appModule.match(importsPattern);
|
|
391
361
|
if (importsMatch) {
|
|
392
362
|
const existingImports = importsMatch[2].trim();
|
|
393
|
-
const renderModuleConfig =
|
|
363
|
+
const renderModuleConfig = vitePort === 5173 ? "RenderModule.forRoot()" : `RenderModule.forRoot({ vite: { port: ${vitePort} } })`;
|
|
394
364
|
if (existingImports === "") {
|
|
395
365
|
appModule = appModule.replace(importsPattern, `$1${renderModuleConfig}`);
|
|
396
366
|
} else {
|
|
@@ -434,15 +404,15 @@ ${serverConfig}build: {
|
|
|
434
404
|
packageJson.scripts["build:server"] = `vite build --ssr ${viewsDir}/entry-server.tsx --outDir dist/server`;
|
|
435
405
|
shouldUpdate = true;
|
|
436
406
|
}
|
|
437
|
-
if (
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
407
|
+
if (!packageJson.scripts["dev:vite"]) {
|
|
408
|
+
packageJson.scripts["dev:vite"] = `vite --port ${vitePort}`;
|
|
409
|
+
shouldUpdate = true;
|
|
410
|
+
}
|
|
411
|
+
if (!packageJson.scripts["dev:nest"]) {
|
|
412
|
+
packageJson.scripts["dev:nest"] = "nest start --watch --watchAssets --preserveWatchOutput";
|
|
413
|
+
shouldUpdate = true;
|
|
414
|
+
}
|
|
415
|
+
if (!packageJson.scripts["start:dev"] || !packageJson.scripts["start:dev"].includes("concurrently")) {
|
|
446
416
|
packageJson.scripts["start:dev"] = 'concurrently --raw -n vite,nest -c cyan,green "pnpm:dev:vite" "pnpm:dev:nest"';
|
|
447
417
|
shouldUpdate = true;
|
|
448
418
|
}
|
|
@@ -475,16 +445,14 @@ ${serverConfig}build: {
|
|
|
475
445
|
react: "^19.0.0",
|
|
476
446
|
"react-dom": "^19.0.0",
|
|
477
447
|
vite: "^7.0.0",
|
|
478
|
-
"@vitejs/plugin-react": "^4.0.0"
|
|
448
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
449
|
+
"http-proxy-middleware": "^3.0.0"
|
|
479
450
|
};
|
|
480
451
|
const requiredDevDeps = {
|
|
481
452
|
"@types/react": "^19.0.0",
|
|
482
|
-
"@types/react-dom": "^19.0.0"
|
|
453
|
+
"@types/react-dom": "^19.0.0",
|
|
454
|
+
concurrently: "^9.0.0"
|
|
483
455
|
};
|
|
484
|
-
if (integrationType === "separate") {
|
|
485
|
-
requiredDeps["http-proxy-middleware"] = "^3.0.0";
|
|
486
|
-
requiredDevDeps["concurrently"] = "^9.0.0";
|
|
487
|
-
}
|
|
488
456
|
const missingDeps = [];
|
|
489
457
|
const missingDevDeps = [];
|
|
490
458
|
const allDeps = {
|
|
@@ -549,17 +517,12 @@ ${serverConfig}build: {
|
|
|
549
517
|
consola.log(" @Get()");
|
|
550
518
|
consola.log(" @Render(Home)");
|
|
551
519
|
consola.log(' home() { return { message: "Hello" }; }');
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
consola.log(" Terminal 2: pnpm dev:nest");
|
|
559
|
-
} else {
|
|
560
|
-
consola.info("\n3. Start the dev server: pnpm start:dev");
|
|
561
|
-
consola.info(" (Vite middleware will be integrated into NestJS)");
|
|
562
|
-
}
|
|
520
|
+
consola.info("\n3. Start development with HMR:");
|
|
521
|
+
consola.log(" pnpm start:dev");
|
|
522
|
+
consola.info(` This runs both Vite (port ${vitePort}) and NestJS concurrently`);
|
|
523
|
+
consola.info("\n Or run them separately:");
|
|
524
|
+
consola.log(" Terminal 1: pnpm dev:vite");
|
|
525
|
+
consola.log(" Terminal 2: pnpm dev:nest");
|
|
563
526
|
}
|
|
564
527
|
});
|
|
565
528
|
runMain(main);
|