@@ -29,6 +29,9 @@ const ROUTER_TEMPLATE_PATH = join(__dirname, "lib", "routerTemplate.js")
29
29
// The folder name of the NextRouter Netlify function
30
30
const ROUTER_FUNCTION_NAME = "nextRouter"
31
31
32
+ console . log ( "\x1b[1m🚀 Next on Netlify 🚀\x1b[22m" )
33
+ console . log ( ` * Functions directory: ${ FUNCTIONS_PATH } ` )
34
+ console . log ( ` * Publish directory: ${ OUTPUT_PATH } ` )
32
35
33
36
// 1. Get a collection of our NextJS pages
34
37
// For each page, evaluate:
@@ -51,6 +54,7 @@ const htmlPages = filteredPages.filter(({ isHTML }) => isHTML)
51
54
52
55
53
56
// 2. SSR Setup
57
+ console . log ( `\x1b[1m💫 Preparing Netlify Function for SSR pages: ${ join ( FUNCTIONS_PATH , ROUTER_FUNCTION_NAME ) } \x1b[22m` )
54
58
55
59
// 2.1 SSR Setup: Clean existing Netlify function folder
56
60
emptyDirSync (
@@ -66,6 +70,8 @@ copySync(
66
70
// 2.3 SSR Setup: Copy SSR pages to functions/_next/pages
67
71
// From there, they can be served by our nextRouter Netlify function.
68
72
ssrPages . forEach ( ( { file } ) => {
73
+ console . log ( ` > ${ file } ` )
74
+
69
75
copySync (
70
76
join ( NEXT_DIST_DIR , "serverless" , file ) ,
71
77
join ( FUNCTIONS_PATH , ROUTER_FUNCTION_NAME , file )
@@ -99,12 +105,18 @@ writeFileSync(
99
105
emptyDirSync ( OUTPUT_PATH )
100
106
101
107
// 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` )
103
110
copySync ( PUBLIC_PATH , OUTPUT_PATH )
111
+ }
104
112
105
113
// 3.3 HTML Setup: Copy HTML pages to the output folder
106
114
// 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
+
107
117
htmlPages . forEach ( ( { file } ) => {
118
+ console . log ( ` > ${ file } ` )
119
+
108
120
// The path to the file, relative to the pages directory
109
121
const relativePath = relative ( "pages" , file )
110
122
@@ -120,6 +132,8 @@ htmlPages.forEach(({ file }) => {
120
132
121
133
122
134
// 4. Prepare NextJS static assets
135
+ console . log ( `\x1b[1m💼 Copying static NextJS assets to ${ OUTPUT_PATH } \x1b[22m` )
136
+
123
137
// Copy the NextJS' static assets from /.next/static to /out/_next/static.
124
138
// These need to be available for NextJS to work.
125
139
copySync (
@@ -133,6 +147,8 @@ copySync(
133
147
134
148
135
149
// 5. Generate the _redirects file
150
+ console . log ( "\x1b[1m🔀 Setting up redirects\x1b[22m" )
151
+
136
152
// These redirects route all requests to the appropriate location: Either the
137
153
// nextRouter Netlify function or one of our static HTML pages. They are merged
138
154
// with the _redirects file from the public/ folder, so you can still define
@@ -146,7 +162,11 @@ const htmlRedirects = htmlPages.map(({ route, file }) => {
146
162
const ssrRedirects = ssrPages . map ( ( { route } ) => (
147
163
`${ route } /.netlify/functions/${ ROUTER_FUNCTION_NAME } 200`
148
164
) )
149
- const nextjsRedirects = [ ...htmlRedirects , ...ssrRedirects ] . join ( "\n" )
165
+ const nextjsRedirects = [ ...htmlRedirects , ...ssrRedirects ]
166
+
167
+ nextjsRedirects . forEach ( redirect => (
168
+ console . log ( ` ${ redirect } ` )
169
+ ) )
150
170
151
171
// Read user-defined redirects
152
172
let userRedirects = ""
@@ -156,7 +176,11 @@ if(existsSync(USER_REDIRECTS_PATH)) {
156
176
157
177
writeFileSync (
158
178
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" )
162
182
)
183
+
184
+
185
+ // Done!
186
+ console . log ( "\x1b[1m✅ Success! All done!\x1b[22m" )
0 commit comments