Skip to content

Commit 707bbab

Browse files
lobsterkatielforst
andauthored
fix(nextjs): Use basePath for assetPrefix if needed (#6424)
Co-authored-by: Luca Forstner <[email protected]>
1 parent 6e09ffe commit 707bbab

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: packages/nextjs/src/config/webpack.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ function addRewriteFramesLoader(
679679
target: 'server' | 'client',
680680
userNextConfig: NextConfigObject,
681681
): void {
682+
// Nextjs will use `basePath` in place of `assetPrefix` if it's defined but `assetPrefix` is not
683+
const assetPrefix = userNextConfig.assetPrefix || userNextConfig.basePath || '';
682684
const replacements = {
683685
server: [
684686
[
@@ -693,9 +695,7 @@ function addRewriteFramesLoader(
693695
'__ASSET_PREFIX_PATH__',
694696
// Get the path part of `assetPrefix`, minus any trailing slash. (We use a placeholder for the origin if
695697
// `assetPreix` doesn't include one. Since we only care about the path, it doesn't matter what it is.)
696-
userNextConfig.assetPrefix
697-
? new URL(userNextConfig.assetPrefix, 'http://dogs.are.great').pathname.replace(/\/$/, '')
698-
: '',
698+
assetPrefix ? new URL(assetPrefix, 'http://dogs.are.great').pathname.replace(/\/$/, '') : '',
699699
],
700700
],
701701
};

0 commit comments

Comments
 (0)