@@ -12,27 +12,30 @@ const copyDynamicImportChunks = async (functionPath) => {
12
12
const filesWP4 = readdirSync ( chunksPathWebpack4 )
13
13
const chunkRegexWP4 = new RegExp ( / ^ ( \. ? [ - $ ~ \w ] + ) + \. j s $ / g)
14
14
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
+ }
15
19
filesWP4 . forEach ( ( file ) => {
16
20
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 ) , {
23
22
overwrite : false ,
24
23
errorOnExist : true ,
25
24
} )
26
25
}
27
26
} )
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
28
30
const chunksPathWebpack5 = join ( nextDistDir , 'serverless' , 'chunks' )
29
31
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
+
30
37
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 ) , {
36
39
overwrite : false ,
37
40
errorOnExist : true ,
38
41
} )
0 commit comments