@nestjs-ssr/react 0.2.6 → 0.3.1

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/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
- integration: {
36
+ port: {
37
37
  type: "string",
38
- description: 'Integration type: "separate" (Vite as separate server) or "integrated" (Vite bundled with NestJS)'
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
- if (integrationType === "separate") {
163
- consola.consola.log(" server: {");
164
- consola.consola.log(" port: 5173,");
165
- consola.consola.log(" strictPort: true,");
166
- consola.consola.log(" hmr: { port: 5173 },");
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
- ${serverConfig}build: {
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 = integrationType === "separate" ? "RenderModule.forRoot({ vite: { mode: 'proxy', port: 5173 } })" : "RenderModule.forRoot()";
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 (integrationType === "separate") {
441
- if (!packageJson.scripts["dev:vite"]) {
442
- packageJson.scripts["dev:vite"] = "vite --port 5173";
443
- shouldUpdate = true;
444
- }
445
- if (!packageJson.scripts["dev:nest"]) {
446
- packageJson.scripts["dev:nest"] = "nest start --watch --watchAssets --preserveWatchOutput";
447
- shouldUpdate = true;
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
- if (integrationType === "separate") {
556
- consola.consola.info("\n3. Start development with HMR:");
557
- consola.consola.log(" pnpm start:dev");
558
- consola.consola.info(" This runs both Vite (port 5173) and NestJS concurrently");
559
- consola.consola.info("\n Or run them separately:");
560
- consola.consola.log(" Terminal 1: pnpm dev:vite");
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
- integration: {
33
+ port: {
34
34
  type: "string",
35
- description: 'Integration type: "separate" (Vite as separate server) or "integrated" (Vite bundled with NestJS)'
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
- if (integrationType === "separate") {
160
- consola.log(" server: {");
161
- consola.log(" port: 5173,");
162
- consola.log(" strictPort: true,");
163
- consola.log(" hmr: { port: 5173 },");
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
- ${serverConfig}build: {
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 = integrationType === "separate" ? "RenderModule.forRoot({ vite: { mode: 'proxy', port: 5173 } })" : "RenderModule.forRoot()";
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 (integrationType === "separate") {
438
- if (!packageJson.scripts["dev:vite"]) {
439
- packageJson.scripts["dev:vite"] = "vite --port 5173";
440
- shouldUpdate = true;
441
- }
442
- if (!packageJson.scripts["dev:nest"]) {
443
- packageJson.scripts["dev:nest"] = "nest start --watch --watchAssets --preserveWatchOutput";
444
- shouldUpdate = true;
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
- if (integrationType === "separate") {
553
- consola.info("\n3. Start development with HMR:");
554
- consola.log(" pnpm start:dev");
555
- consola.info(" This runs both Vite (port 5173) and NestJS concurrently");
556
- consola.info("\n Or run them separately:");
557
- consola.log(" Terminal 1: pnpm dev:vite");
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);