File tree Expand file tree Collapse file tree 5 files changed +19
-12
lines changed Expand file tree Collapse file tree 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+
16export default class CacheHandler {
27 options : any
38 cache : Map < string , any >
Original file line number Diff line number Diff line change @@ -3,13 +3,17 @@ import { readFile } from 'node:fs/promises'
33import { TASK_DIR } from './constants.js'
44
55/**
6- * Enable Next.js standalone mode
6+ * Enable standalone mode at build-time
77 */
88export const setBuildConfig = ( ) => {
99 process . env . NEXT_PRIVATE_STANDALONE = 'true'
1010}
1111
12+ /**
13+ * Configure the request-time custom cache handler
14+ */
1215export const setRequestConfig = async ( ) => {
16+ // get config from the build output
1317 const runtimeConfig = JSON . parse ( await readFile ( `${ TASK_DIR } /.next/required-server-files.json` , 'utf-8' ) )
1418
1519 // set the path to the cache handler
@@ -18,6 +22,6 @@ export const setRequestConfig = async () => {
1822 incrementalCacheHandlerPath : `${ TASK_DIR } /dist/handlers/cache.cjs` ,
1923 }
2024
21- // set config from the build output
25+ // set config
2226 process . env . __NEXT_PRIVATE_STANDALONE_CONFIG = JSON . stringify ( runtimeConfig . config )
2327}
Original file line number Diff line number Diff line change @@ -6,16 +6,16 @@ import { copySync, moveSync } from 'fs-extra/esm'
66import { BUILD_DIR } from './constants.js'
77
88/**
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
1010 */
11- export const moveBuildOutput = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
11+ export const stashBuildOutput = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
1212 moveSync ( PUBLISH_DIR , BUILD_DIR , { overwrite : true } )
1313}
1414
1515/**
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
1717 */
18- export const moveStaticAssets = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
18+ export const publishStaticAssets = ( { PUBLISH_DIR } : NetlifyPluginConstants ) => {
1919 if ( existsSync ( 'public' ) ) {
2020 copySync ( 'public' , PUBLISH_DIR )
2121 }
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ const pkg = readJsonSync(`${PLUGIN_DIR}/package.json`)
99
1010/**
1111 * Create a Netlify function to run the Next.js server
12- * @param publishDir The publish directory
13- * @param config Netlify config
1412 */
1513export const createServerHandler = async ( ) => {
1614 // clear the handler directory
@@ -43,7 +41,7 @@ export const createServerHandler = async () => {
4341 version : 1 ,
4442 } )
4543
46- // config ESM
44+ // configure ESM
4745 writeFileSync ( `${ SERVER_HANDLER_DIR } /package.json` , JSON . stringify ( { type : 'module' } ) )
4846
4947 // write the root handler file
Original file line number Diff line number Diff line change 11import type { NetlifyPluginOptions } from '@netlify/build'
22
33import { setBuildConfig } from './helpers/config.js'
4- import { moveStaticAssets , moveBuildOutput } from './helpers/files.js'
4+ import { publishStaticAssets , stashBuildOutput } from './helpers/files.js'
55import { createServerHandler } from './helpers/functions.js'
66
77type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { featureFlags ?: Record < string , unknown > }
@@ -11,7 +11,7 @@ export const onPreBuild = () => {
1111}
1212
1313export const onBuild = async ( { constants } : NetlifyPluginOptionsWithFlags ) => {
14- moveBuildOutput ( constants )
15- moveStaticAssets ( constants )
14+ stashBuildOutput ( constants )
15+ publishStaticAssets ( constants )
1616 await createServerHandler ( )
1717}
You can’t perform that action at this time.
0 commit comments