Skip to content

Commit b7a74f8

Browse files
authored
fix: pass server config to Rsbuild (#584)
1 parent e667662 commit b7a74f8

File tree

13 files changed

+103
-0
lines changed

13 files changed

+103
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ async function initMFRsbuild(
3333
...(rslibConfig.plugins || []),
3434
...(mfRsbuildConfig.config.plugins || []),
3535
],
36+
server: mergeRsbuildConfig(
37+
rslibConfig.server,
38+
mfRsbuildConfig.config.server,
39+
),
3640
},
3741
});
42+
3843
const devServer = await rsbuildInstance.startDevServer();
3944

4045
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 rsbuildConfigContent = await fse.readFile(rsbuildConfigFile, 'utf-8');
38+
expect(rsbuildConfigContent).toContain(`base: '/'`);
39+
expect(rsbuildConfigContent).toContain('open: true');
40+
expect(rsbuildConfigContent).toContain('port: 3002');
41+
expect(rsbuildConfigContent).toContain('printUrls: false');
42+
});
43+
});
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)