@@ -646,8 +646,8 @@ function setUpModuleRules(newConfig: WebpackConfigObject): WebpackConfigObjectWi
646
646
}
647
647
648
648
/**
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 `.
651
651
*
652
652
* @param newConfig The webpack config object being constructed
653
653
* @param target Either 'server' or 'client'
@@ -667,6 +667,16 @@ function addRewriteFramesLoader(
667
667
userNextConfig . distDir ?. replace ( / \\ / g, '\\\\' ) || '.next' ,
668
668
] ,
669
669
] ,
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
+ ] ,
670
680
} ;
671
681
672
682
newConfig . module . rules . push ( {
@@ -676,8 +686,7 @@ function addRewriteFramesLoader(
676
686
loader : path . resolve ( __dirname , 'loaders/prefixLoader.js' ) ,
677
687
options : {
678
688
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 ] ,
681
690
} ,
682
691
} ,
683
692
] ,
0 commit comments