Skip to content

Commit 5856689

Browse files
committed
fix: pass server config to Rsbuild
1 parent 43c88d8 commit 5856689

File tree

13 files changed

+113
-0
lines changed

13 files changed

+113
-0
lines changed

packages/core/src/cli/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function build(
1212
const rsbuildInstance = await createRsbuild({
1313
rsbuildConfig: {
1414
plugins: config.plugins,
15+
server: config.server,
1516
environments: pruneEnvironments(environments, options.lib),
1617
},
1718
});

packages/core/src/cli/inspect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export async function inspect(
1111
const rsbuildInstance = await createRsbuild({
1212
rsbuildConfig: {
1313
plugins: config.plugins,
14+
server: config.server,
1415
environments: pruneEnvironments(environments, options.lib),
1516
},
1617
});

packages/core/src/cli/mf.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createRsbuild, mergeRsbuildConfig } from '@rsbuild/core';
22
import type { RsbuildConfig, RsbuildInstance } from '@rsbuild/core';
3+
import merge from 'node_modules/@rsbuild/core/compiled/webpack-merge';
34
import { composeCreateRsbuildConfig } from '../config';
45
import type { RslibConfig } from '../types';
56
import { onBeforeRestart } from './restart';
@@ -33,8 +34,14 @@ async function initMFRsbuild(
3334
...(rslibConfig.plugins || []),
3435
...(mfRsbuildConfig.config.plugins || []),
3536
],
37+
server: mergeRsbuildConfig(
38+
rslibConfig.server,
39+
mfRsbuildConfig.config.server,
40+
),
3641
},
3742
});
43+
console.log('rslibConfig.server: ', rslibConfig.server);
44+
console.log('mfRsbuildConfig.config.server: ', mfRsbuildConfig.config.server);
3845
const devServer = await rsbuildInstance.startDevServer();
3946

4047
onBeforeRestart(devServer.server.close);

packages/core/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ export async function composeCreateRsbuildConfig(
13351335
const {
13361336
lib: libConfigsArray,
13371337
plugins: sharedPlugins,
1338+
server,
13381339
...sharedRsbuildConfig
13391340
} = rslibConfig;
13401341

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "server-basic-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}

tests/integration/server/basic/public/logo.svg

Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig()],
6+
server: {
7+
publicDir: {
8+
copyOnBuild: false,
9+
},
10+
},
11+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { exec } from 'node:child_process';
2+
import { existsSync } from 'node:fs';
3+
import { join } from 'node:path';
4+
import fse from 'fs-extra';
5+
import { awaitFileExists, buildAndGetResults } from 'test-helper';
6+
import { describe, expect, test } from 'vitest';
7+
8+
describe('server config', async () => {
9+
test('basic config', async () => {
10+
const fixturePath = join(__dirname, 'basic');
11+
await buildAndGetResults({ fixturePath });
12+
13+
// Check if logo.svg in public is copied to dist/esm
14+
const logoPath = join(__dirname, 'dist', 'esm', 'logo.svg');
15+
const logoExists = existsSync(logoPath);
16+
expect(logoExists).toBe(false);
17+
});
18+
19+
test('mf dev command', async () => {
20+
const fixturePath = join(__dirname, 'mf-dev');
21+
const distPath = join(fixturePath, 'dist');
22+
const rsbuildConfigFile = join(distPath, '.rsbuild/rsbuild.config.mjs');
23+
fse.removeSync(distPath);
24+
25+
const childProcess = exec('npx rslib mf dev', {
26+
cwd: fixturePath,
27+
env: {
28+
...process.env,
29+
DEBUG: 'rsbuild',
30+
},
31+
});
32+
33+
await awaitFileExists(rsbuildConfigFile);
34+
childProcess.kill();
35+
36+
// Check if the server config is merged correctly
37+
const rsbuildConfig = await import(rsbuildConfigFile);
38+
expect(rsbuildConfig.default.server).toMatchInlineSnapshot(`
39+
{
40+
"base": "/",
41+
"compress": true,
42+
"host": "0.0.0.0",
43+
"htmlFallback": "index",
44+
"open": true,
45+
"port": 3002,
46+
"printUrls": false,
47+
"strictPort": false,
48+
}
49+
`);
50+
});
51+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "server-mf-dev-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
{
7+
format: 'mf',
8+
server: {
9+
port: 3002,
10+
printUrls: false,
11+
},
12+
},
13+
],
14+
server: {
15+
port: 3001,
16+
open: true,
17+
},
18+
plugins: [
19+
pluginModuleFederation({
20+
name: 'test',
21+
}),
22+
],
23+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';

0 commit comments

Comments
 (0)