File tree 5 files changed +19
-12
lines changed
5 files changed +19
-12
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Netlify Cache Handler
3
+ * (CJS format because Next.js doesn't support ESM yet)
4
+ */
5
+
1
6
export default class CacheHandler {
2
7
options : any
3
8
cache : Map < string , any >
Original file line number Diff line number Diff line change @@ -3,13 +3,17 @@ import { readFile } from 'node:fs/promises'
3
3
import { TASK_DIR } from './constants.js'
4
4
5
5
/**
6
- * Enable Next.js standalone mode
6
+ * Enable standalone mode at build-time
7
7
*/
8
8
export const setBuildConfig = ( ) => {
9
9
process . env . NEXT_PRIVATE_STANDALONE = 'true'
10
10
}
11
11
12
+ /**
13
+ * Configure the request-time custom cache handler
14
+ */
12
15
export const setRequestConfig = async ( ) => {
16
+ // get config from the build output
13
17
const runtimeConfig = JSON . parse ( await readFile ( `${ TASK_DIR } /.next/required-server-files.json` , 'utf-8' ) )
14
18
15
19
// set the path to the cache handler
@@ -18,6 +22,6 @@ export const setRequestConfig = async () => {
18
22
incrementalCacheHandlerPath : `${ TASK_DIR } /dist/handlers/cache.cjs` ,
19
23
}
20
24
21
- // set config from the build output
25
+ // set config
22
26
process . env . __NEXT_PRIVATE_STANDALONE_CONFIG = JSON . stringify ( runtimeConfig . config )
23
27
}
Original file line number Diff line number Diff line change @@ -6,16 +6,16 @@ import { copySync, moveSync } from 'fs-extra/esm'
6
6
import { BUILD_DIR } from './constants.js'
7
7
8
8
/**
9
- * Move the Next.js build output to a temporary directory
9
+ * Move the Next.js build output from the publish dir to a temp dir
10
10
*/
11
- export const moveBuildOutput = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
11
+ export const stashBuildOutput = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
12
12
moveSync ( PUBLISH_DIR , BUILD_DIR , { overwrite : true } )
13
13
}
14
14
15
15
/**
16
- * Move static assets so they are uploaded to the Netlify CDN
16
+ * Move static assets to the publish dir so they upload to the CDN
17
17
*/
18
- export const moveStaticAssets = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
18
+ export const publishStaticAssets = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
19
19
if ( existsSync ( 'public' ) ) {
20
20
copySync ( 'public' , PUBLISH_DIR )
21
21
}
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ const pkg = readJsonSync(`${PLUGIN_DIR}/package.json`)
9
9
10
10
/**
11
11
* Create a Netlify function to run the Next.js server
12
- * @param publishDir The publish directory
13
- * @param config Netlify config
14
12
*/
15
13
export const createServerHandler = async ( ) => {
16
14
// clear the handler directory
@@ -43,7 +41,7 @@ export const createServerHandler = async () => {
43
41
version : 1 ,
44
42
} )
45
43
46
- // config ESM
44
+ // configure ESM
47
45
writeFileSync ( `${ SERVER_HANDLER_DIR } /package.json` , JSON . stringify ( { type : 'module' } ) )
48
46
49
47
// write the root handler file
Original file line number Diff line number Diff line change 1
1
import type { NetlifyPluginOptions } from '@netlify/build'
2
2
3
3
import { setBuildConfig } from './helpers/config.js'
4
- import { moveStaticAssets , moveBuildOutput } from './helpers/files.js'
4
+ import { publishStaticAssets , stashBuildOutput } from './helpers/files.js'
5
5
import { createServerHandler } from './helpers/functions.js'
6
6
7
7
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { featureFlags ?: Record < string , unknown > }
@@ -11,7 +11,7 @@ export const onPreBuild = () => {
11
11
}
12
12
13
13
export const onBuild = async ( { constants } : NetlifyPluginOptionsWithFlags ) => {
14
- moveBuildOutput ( constants )
15
- moveStaticAssets ( constants )
14
+ stashBuildOutput ( constants )
15
+ publishStaticAssets ( constants )
16
16
await createServerHandler ( )
17
17
}
You can’t perform that action at this time.
0 commit comments