@@ -29,6 +29,9 @@ const ROUTER_TEMPLATE_PATH = join(__dirname, "lib", "routerTemplate.js")
2929// The folder name of the NextRouter Netlify function
3030const ROUTER_FUNCTION_NAME = "nextRouter"
3131
32+ console . log ( "\x1b[1m🚀 Next on Netlify 🚀\x1b[22m" )
33+ console . log ( ` * Functions directory: ${ FUNCTIONS_PATH } ` )
34+ console . log ( ` * Publish directory: ${ OUTPUT_PATH } ` )
3235
3336// 1. Get a collection of our NextJS pages
3437// For each page, evaluate:
@@ -51,6 +54,7 @@ const htmlPages = filteredPages.filter(({ isHTML }) => isHTML)
5154
5255
5356// 2. SSR Setup
57+ console . log ( `\x1b[1m💫 Preparing Netlify Function for SSR pages: ${ join ( FUNCTIONS_PATH , ROUTER_FUNCTION_NAME ) } \x1b[22m` )
5458
5559// 2.1 SSR Setup: Clean existing Netlify function folder
5660emptyDirSync (
@@ -66,6 +70,8 @@ copySync(
6670// 2.3 SSR Setup: Copy SSR pages to functions/_next/pages
6771// From there, they can be served by our nextRouter Netlify function.
6872ssrPages . forEach ( ( { file } ) => {
73+ console . log ( ` > ${ file } ` )
74+
6975 copySync (
7076 join ( NEXT_DIST_DIR , "serverless" , file ) ,
7177 join ( FUNCTIONS_PATH , ROUTER_FUNCTION_NAME , file )
@@ -99,12 +105,18 @@ writeFileSync(
99105emptyDirSync ( OUTPUT_PATH )
100106
101107// 3.2 HTML Setup: Copy files from public folder to output path
102- if ( existsSync ( PUBLIC_PATH ) )
108+ if ( existsSync ( PUBLIC_PATH ) ) {
109+ console . log ( `\x1b[1m🌍️ Copying ${ PUBLIC_PATH } folder to ${ OUTPUT_PATH } \x1b[22m` )
103110 copySync ( PUBLIC_PATH , OUTPUT_PATH )
111+ }
104112
105113// 3.3 HTML Setup: Copy HTML pages to the output folder
106114// These are static, so they do not need to be handled by our nextRouter.
115+ console . log ( `\x1b[1m🔥 Writing pre-rendered HTML pages to ${ OUTPUT_PATH } \x1b[22m` )
116+
107117htmlPages . forEach ( ( { file } ) => {
118+ console . log ( ` > ${ file } ` )
119+
108120 // The path to the file, relative to the pages directory
109121 const relativePath = relative ( "pages" , file )
110122
@@ -120,6 +132,8 @@ htmlPages.forEach(({ file }) => {
120132
121133
122134// 4. Prepare NextJS static assets
135+ console . log ( `\x1b[1m💼 Copying static NextJS assets to ${ OUTPUT_PATH } \x1b[22m` )
136+
123137// Copy the NextJS' static assets from /.next/static to /out/_next/static.
124138// These need to be available for NextJS to work.
125139copySync (
@@ -133,6 +147,8 @@ copySync(
133147
134148
135149// 5. Generate the _redirects file
150+ console . log ( "\x1b[1m🔀 Setting up redirects\x1b[22m" )
151+
136152// These redirects route all requests to the appropriate location: Either the
137153// nextRouter Netlify function or one of our static HTML pages. They are merged
138154// with the _redirects file from the public/ folder, so you can still define
@@ -146,7 +162,11 @@ const htmlRedirects = htmlPages.map(({ route, file }) => {
146162const ssrRedirects = ssrPages . map ( ( { route } ) => (
147163 `${ route } /.netlify/functions/${ ROUTER_FUNCTION_NAME } 200`
148164) )
149- const nextjsRedirects = [ ...htmlRedirects , ...ssrRedirects ] . join ( "\n" )
165+ const nextjsRedirects = [ ...htmlRedirects , ...ssrRedirects ]
166+
167+ nextjsRedirects . forEach ( redirect => (
168+ console . log ( ` ${ redirect } ` )
169+ ) )
150170
151171// Read user-defined redirects
152172let userRedirects = ""
@@ -156,7 +176,11 @@ if(existsSync(USER_REDIRECTS_PATH)) {
156176
157177writeFileSync (
158178 join ( OUTPUT_PATH , "_redirects" ) ,
159- userRedirects + "\n\n" +
160- "# Next-on-Netlify Redirects" + "\n" +
161- nextjsRedirects
179+ userRedirects + "\n\n" +
180+ "# Next-on-Netlify Redirects" + "\n" +
181+ nextjsRedirects . join ( "\n" )
162182)
183+
184+
185+ // Done!
186+ console . log ( "\x1b[1m✅ Success! All done!\x1b[22m" )
0 commit comments