Skip to content

Commit 8a419a0

Browse files
authored
fix(angular-rspack): dev-server works for ssr (#34)
1 parent 70f4ba2 commit 8a419a0

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed
+22-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
module.exports = () => {
22
if (global.NX_GRAPH_CREATION === undefined) {
33
const { createConfig } = require('@nx/angular-rspack');
4-
return createConfig({
5-
options: {
6-
browser: './src/main.ts',
7-
index: './src/index.html',
8-
server: './src/main.server.ts',
9-
ssr: { entry: './src/server.ts' },
4+
return createConfig(
5+
{
6+
options: {
7+
browser: './src/main.ts',
8+
index: './src/index.html',
9+
server: './src/main.server.ts',
10+
ssr: { entry: './src/server.ts' },
11+
assets: [
12+
{
13+
glob: '**/*',
14+
input: './public',
15+
},
16+
],
17+
},
1018
},
11-
});
19+
{
20+
development: {
21+
options: {
22+
optimization: false,
23+
},
24+
},
25+
}
26+
);
1227
}
1328
return {};
1429
};

packages/angular-rspack/src/lib/config/create-config.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export async function _createConfig(
8585
): Promise<Configuration[]> {
8686
const normalizedOptions = normalizeOptions(options);
8787
const isProduction = process.env['NODE_ENV'] === 'production';
88+
const isDevServer = process.env['WEBPACK_SERVE'];
8889
const hashFormat = getOutputHashFormat(normalizedOptions.outputHashing);
8990
const { root } = normalizedOptions;
9091

@@ -175,6 +176,7 @@ export async function _createConfig(
175176
if (normalizedOptions.hasServer) {
176177
const serverConfig: Configuration = {
177178
...defaultConfig,
179+
name: 'server',
178180
target: 'node',
179181
entry: {
180182
server: {
@@ -236,7 +238,7 @@ export async function _createConfig(
236238
optimization: {
237239
chunkIds: normalizedOptions.namedChunks ? 'named' : 'deterministic',
238240
moduleIds: 'deterministic',
239-
...(normalizedOptions.optimization
241+
...(normalizedOptions.optimization && !isDevServer
240242
? {
241243
minimize: true,
242244
runtimeChunk: 'single',
@@ -272,7 +274,6 @@ export async function _createConfig(
272274
new SwcJsMinimizerRspackPlugin({
273275
minimizerOptions: {
274276
minify: true,
275-
mangle: true,
276277
compress: {
277278
passes: 2,
278279
},
@@ -305,6 +306,10 @@ export async function _createConfig(
305306

306307
const browserConfig = {
307308
...defaultConfig,
309+
name: 'browser',
310+
...(normalizedOptions.hasServer && isDevServer
311+
? { dependencies: ['server'] }
312+
: {}),
308313
target: 'web',
309314
entry: {
310315
main: {
@@ -380,7 +385,7 @@ export async function _createConfig(
380385
optimization: {
381386
chunkIds: normalizedOptions.namedChunks ? 'named' : 'deterministic',
382387
moduleIds: 'deterministic',
383-
...(normalizedOptions.optimization
388+
...(normalizedOptions.optimization && !isDevServer
384389
? {
385390
minimize: true,
386391
runtimeChunk: false,

packages/angular-rspack/src/lib/plugins/angular-ssr-dev-server.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ChildProcess, fork } from 'child_process';
33
import { SsrReloadServer } from './server/ssr-reload-server';
44
import { OutputPath } from '../models';
55
import { join } from 'node:path';
6+
import { existsSync } from 'node:fs';
67

78
const PLUGIN_NAME = 'AngularSsrDevServer';
89
export class AngularSsrDevServer implements RspackPluginInstance {
@@ -36,6 +37,9 @@ export class AngularSsrDevServer implements RspackPluginInstance {
3637
this.#devServerProcess = undefined;
3738
await new Promise<void>((res) => setTimeout(res, 50));
3839
}
40+
if (!existsSync(serverPath)) {
41+
await new Promise<void>((res) => setTimeout(res, 50));
42+
}
3943
this.#devServerProcess = fork(serverPath);
4044
this.#devServerProcess.on('spawn', () => {
4145
this.#wsServer.sendReload();

0 commit comments

Comments
 (0)