Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/helpers/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const formatPublicPath = (
withSlash = true,
): string => {
// 'auto' is a magic value in Rspack and we should not add trailing slash
if (publicPath === 'auto') {
// Empty string is a valid value representing a relative path and should be preserved (important for node targets)
if (publicPath === 'auto' || publicPath === '') {
return publicPath;
}

Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/plugins/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,42 @@ import type {

function getPublicPath({
isDev,
isServer,
config,
context,
}: {
isDev: boolean;
isServer: boolean;
config: NormalizedEnvironmentConfig;
context: RsbuildContext;
}) {
const { dev, output, server } = config;

// For server targets (node), use empty string or explicit assetPrefix to enable relative paths
// This is important for worker_threads and other node-specific imports
// See: https://github.com/web-infra-dev/rsbuild/issues/6539
if (isServer) {
if (!isDev && typeof output.assetPrefix === 'string') {
return output.assetPrefix;
}
// For node targets in dev mode, use empty string by default
return '';
}

let publicPath = DEFAULT_ASSET_PREFIX;

// If `mode` is `production` or `none`, use `output.assetPrefix`
if (!isDev) {
if (typeof output.assetPrefix === 'string') {
publicPath = output.assetPrefix;
}
} else if (
typeof output.assetPrefix === 'string' &&
output.assetPrefix !== DEFAULT_ASSET_PREFIX
) {
// In dev mode, prefer environment-specific `output.assetPrefix` over `dev.assetPrefix`
// but only if it's explicitly set to a non-default value
publicPath = output.assetPrefix;
} else if (typeof dev.assetPrefix === 'string') {
publicPath = dev.assetPrefix;
} else if (dev.assetPrefix) {
Expand Down Expand Up @@ -83,6 +103,7 @@ export const pluginOutput = (): RsbuildPlugin => ({
const publicPath = getPublicPath({
config,
isDev,
isServer,
context: api.context,
});

Expand Down
Loading