@@ -12,27 +12,30 @@ const copyDynamicImportChunks = async (functionPath) => {
1212 const filesWP4 = readdirSync ( chunksPathWebpack4 )
1313 const chunkRegexWP4 = new RegExp ( / ^ ( \. ? [ - $ ~ \w ] + ) + \. j s $ / g)
1414 const excludeFiles = new Set ( [ 'init-server.js.js' , 'on-error-server.js.js' ] )
15+ const copyPathWP4 = join ( functionPath , 'nextPage' )
16+ if ( filesWP4 . length !== 0 ) {
17+ logTitle ( '💼 Copying WP4 dynamic import chunks to' , copyPathWP4 )
18+ }
1519 filesWP4 . forEach ( ( file ) => {
1620 if ( ! excludeFiles . has ( file ) && chunkRegexWP4 . test ( file ) ) {
17- // WP4 files are looked for one level up (../) in runtime
18- // This is a hack to make the file one level up i.e. with
19- // nextPage/nextPage/index.js, the chunk is moved to the inner nextPage
20- const copyPath = join ( functionPath , 'nextPage' )
21- // logTitle('💼 Copying WP4 dynamic import chunks to', copyPath)
22- copySync ( join ( chunksPathWebpack4 , file ) , join ( copyPath , file ) , {
21+ copySync ( join ( chunksPathWebpack4 , file ) , join ( copyPathWP4 , file ) , {
2322 overwrite : false ,
2423 errorOnExist : true ,
2524 } )
2625 }
2726 } )
27+
28+ // Chunks are copied into the nextPage directory, as a sibling to "pages" or "api".
29+ // This matches the Next output, so that imports work correctly
2830 const chunksPathWebpack5 = join ( nextDistDir , 'serverless' , 'chunks' )
2931 const filesWP5 = existsSync ( chunksPathWebpack5 ) ? readdirSync ( chunksPathWebpack5 ) : [ ]
32+ const copyPathWP5 = join ( functionPath , 'nextPage' , 'chunks' )
33+ if ( filesWP5 . length !== 0 ) {
34+ logTitle ( '💼 Copying WB5 dynamic import chunks to' , copyPathWP5 )
35+ }
36+
3037 filesWP5 . forEach ( ( file ) => {
31- // Chunks are copied into the nextPage directory, as a sibling to pages or api.
32- // This matches the Next output, so that imports work correctly
33- const copyPath = join ( functionPath , 'nextPage' , 'chunks' )
34- // logTitle('💼 Copying WB5 dynamic import chunks to', copyPath)
35- copySync ( join ( chunksPathWebpack5 , file ) , join ( copyPath , file ) , {
38+ copySync ( join ( chunksPathWebpack5 , file ) , join ( copyPathWP5 , file ) , {
3639 overwrite : false ,
3740 errorOnExist : true ,
3841 } )
0 commit comments