Skip to content

Commit e61f1c5

Browse files
committed
fix
1 parent 784f8f9 commit e61f1c5

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

packages/core/src/plugins/output.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function getPublicPath({
5252
}
5353
}
5454

55-
const port = (isProd ? server.port : context.devServer?.port) ?? DEFAULT_PORT;
55+
const defaultPort = server.port ?? DEFAULT_PORT;
56+
const port = isProd ? defaultPort : (context.devServer?.port ?? defaultPort);
5657
return formatPublicPath(replacePortPlaceholder(publicPath, port));
5758
}
5859

packages/core/tests/output.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createStubRsbuild } from '@scripts/test-helper';
2+
import { createRsbuild } from '../src';
23
import { pluginOutput } from '../src/plugins/output';
34

45
describe('plugin-output', () => {
@@ -179,8 +180,8 @@ describe('plugin-output', () => {
179180
});
180181

181182
it('should replace `<port>` placeholder with server.port', async () => {
182-
const rsbuild = await createStubRsbuild({
183-
plugins: [pluginOutput()],
183+
vi.stubEnv('NODE_ENV', 'development');
184+
const rsbuild = await createRsbuild({
184185
rsbuildConfig: {
185186
server: { port: 4000 },
186187
dev: {
@@ -190,12 +191,12 @@ describe('plugin-output', () => {
190191
});
191192
const [config] = await rsbuild.initConfigs();
192193
expect(config?.output?.publicPath).toEqual('http://example-4000.com:4000/');
194+
vi.unstubAllEnvs();
193195
});
194196

195197
it('should replace `<port>` placeholder of `output.assetPrefix` with default port', async () => {
196198
vi.stubEnv('NODE_ENV', 'production');
197-
const rsbuild = await createStubRsbuild({
198-
plugins: [pluginOutput()],
199+
const rsbuild = await createRsbuild({
199200
rsbuildConfig: {
200201
output: {
201202
assetPrefix: 'http://example.com:<port>/',
@@ -205,5 +206,6 @@ describe('plugin-output', () => {
205206

206207
const [config] = await rsbuild.initConfigs();
207208
expect(config?.output?.publicPath).toEqual('http://example.com:3000/');
209+
vi.unstubAllEnvs();
208210
});
209211
});

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ unocss
134134
unpatch
135135
unplugin
136136
unshift
137+
unstub
137138
upath
138139
vitest
139140
vnode

0 commit comments

Comments
 (0)