@@ -646,8 +646,8 @@ function setUpModuleRules(newConfig: WebpackConfigObject): WebpackConfigObjectWi
646646}
647647
648648/**
649- * Support the `distDir` option by making its value (easy to get here at build-time) available to the server SDK's
650- * default `RewriteFrames` instance (which needs it at runtime ), by injecting code to attach it to `global`.
649+ * Support the `distDir` and `assetPrefix` options by making their values (easy to get here at build-time) available at
650+ * runtime (for use by `RewriteFrames` ), by injecting code to attach their values to `global` or `window `.
651651 *
652652 * @param newConfig The webpack config object being constructed
653653 * @param target Either 'server' or 'client'
@@ -667,6 +667,16 @@ function addRewriteFramesLoader(
667667 userNextConfig . distDir ?. replace ( / \\ / g, '\\\\' ) || '.next' ,
668668 ] ,
669669 ] ,
670+ client : [
671+ [
672+ '__ASSET_PREFIX_PATH__' ,
673+ // Get the path part of `assetPrefix`, minus any trailing slash. (We use a placeholder for the origin if
674+ // `assetPreix` doesn't include one. Since we only care about the path, it doesn't matter what it is.)
675+ userNextConfig . assetPrefix
676+ ? new URL ( userNextConfig . assetPrefix , 'http://dogs.are.great' ) . pathname . replace ( / \/ $ / , '' )
677+ : '' ,
678+ ] ,
679+ ] ,
670680 } ;
671681
672682 newConfig . module . rules . push ( {
@@ -676,8 +686,7 @@ function addRewriteFramesLoader(
676686 loader : path . resolve ( __dirname , 'loaders/prefixLoader.js' ) ,
677687 options : {
678688 templatePrefix : `${ target } RewriteFrames` ,
679- // This weird cast will go away as soon as we add the client half of this function in
680- replacements : replacements [ target as 'server' ] ,
689+ replacements : replacements [ target ] ,
681690 } ,
682691 } ,
683692 ] ,
0 commit comments