@@ -83,6 +83,8 @@ export default async function getBaseWebpackConfig(
83
83
const isServerlessTrace = target === 'experimental-serverless-trace'
84
84
const isLikeServerless = isServerless || isServerlessTrace
85
85
86
+ const isProductionServerlessTrace = isServerlessTrace && ! dev && isServer
87
+
86
88
const outputDir = isLikeServerless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY
87
89
const outputPath = path . join ( distDir , isServer ? outputDir : '' )
88
90
const totalPages = Object . keys ( entrypoints ) . length
@@ -403,10 +405,40 @@ export default async function getBaseWebpackConfig(
403
405
...nodePathList , // Support for NODE_PATH environment variable
404
406
] ,
405
407
} ,
408
+ ...( isProductionServerlessTrace
409
+ ? {
410
+ // `@zeit/webpack-asset-relocator-loader` will relocated all assets
411
+ // so we can't let webpack mock this to `/` & `/index.js`.
412
+ //
413
+ // This is not enabled for `target: 'serverless'` for backwards
414
+ // compatibility reasons.
415
+ node : { __dirname : false , __filename : false } ,
416
+ }
417
+ : undefined ) ,
406
418
// @ts -ignore this is filtered
407
419
module : {
408
420
strictExportPresence : true ,
409
421
rules : [
422
+ // This loader relocates all build assets into a new folder since we
423
+ // change the emitted path structure during bundling.
424
+ //
425
+ // This is not enabled for `target: 'serverless'` for backwards
426
+ // compatibility reasons.
427
+ isProductionServerlessTrace && {
428
+ // These extensions have been transformed into traditional JavaScript
429
+ // by prior loaders.
430
+ test : / \. ( t s x | t s | j s | m j s | j s x | n o d e ) $ / ,
431
+ parser : { amd : false } ,
432
+ use : {
433
+ loader : '@zeit/webpack-asset-relocator-loader' ,
434
+ options : {
435
+ outputAssetBase : 'assets' ,
436
+ existingAssetNames : [ ] ,
437
+ wrapperCompatibility : false ,
438
+ production : true ,
439
+ } ,
440
+ } ,
441
+ } ,
410
442
( selectivePageBuilding || config . experimental . terserLoader ) &&
411
443
! isServer && {
412
444
test : / \. ( j s | m j s | j s x ) $ / ,
0 commit comments