@@ -635,8 +635,8 @@ function setUpModuleRules(newConfig: WebpackConfigObject): WebpackConfigObjectWi
635
635
}
636
636
637
637
/**
638
- * Support the `distDir` option by making its value (easy to get here at build-time) available to the server SDK's
639
- * default `RewriteFrames` instance (which needs it at runtime ), by injecting code to attach it to `global`.
638
+ * Support the `distDir` and `assetPrefix` options by making their values (easy to get here at build-time) available at
639
+ * runtime (for use by `RewriteFrames` ), by injecting code to attach their values to `global` or `window `.
640
640
*
641
641
* @param newConfig The webpack config object being constructed
642
642
* @param target Either 'server' or 'client'
@@ -656,6 +656,16 @@ function addRewriteFramesLoader(
656
656
userNextConfig . distDir ?. replace ( / \\ / g, '\\\\' ) || '.next' ,
657
657
] ,
658
658
] ,
659
+ client : [
660
+ [
661
+ '__ASSET_PREFIX_PATH__' ,
662
+ // Get the path part of `assetPrefix`, minus any trailing slash. (We use a placeholder for the origin if
663
+ // `assetPreix` doesn't include one. Since we only care about the path, it doesn't matter what it is.)
664
+ userNextConfig . assetPrefix
665
+ ? new URL ( userNextConfig . assetPrefix , 'http://dogs.are.great' ) . pathname . replace ( / \/ $ / , '' )
666
+ : '' ,
667
+ ] ,
668
+ ] ,
659
669
} ;
660
670
661
671
newConfig . module . rules . push ( {
@@ -665,8 +675,7 @@ function addRewriteFramesLoader(
665
675
loader : path . resolve ( __dirname , 'loaders/prefixLoader.js' ) ,
666
676
options : {
667
677
templatePrefix : `${ target } RewriteFrames` ,
668
- // This weird cast will go away as soon as we add the client half of this function in
669
- replacements : replacements [ target as 'server' ] ,
678
+ replacements : replacements [ target ] ,
670
679
} ,
671
680
} ,
672
681
] ,
0 commit comments