|
1 | 1 | // @ts-check |
2 | | -const { readJSON } = require('fs-extra') |
| 2 | +const { readJSON, existsSync } = require('fs-extra') |
3 | 3 | const { join, dirname, relative } = require('pathe') |
4 | 4 | const slash = require('slash') |
5 | 5 |
|
@@ -79,14 +79,29 @@ exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => { |
79 | 79 | if (i18n) { |
80 | 80 | netlifyConfig.redirects.push({ from: `${basePath}/:locale/_next/static/*`, to: `/static/:splat`, status: 200 }) |
81 | 81 | } |
| 82 | + |
| 83 | + const staticManifest = join(netlifyConfig.build.publish, 'static-manifest.json') |
| 84 | + if (process.env.EXPERIMENTAL_MOVE_STATIC_PAGES && existsSync(staticManifest)) { |
| 85 | + // Static page files need to have a forced redirect for preview mode. Otherwise it's non-forced |
| 86 | + const staticFiles = await readJSON(staticManifest) |
| 87 | + netlifyConfig.redirects.push( |
| 88 | + ...staticFiles.map((file) => ({ |
| 89 | + from: `${basePath}/${file}`, |
| 90 | + to: HANDLER_FUNCTION_PATH, |
| 91 | + status: 200, |
| 92 | + force: true, |
| 93 | + conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] }, |
| 94 | + })), |
| 95 | + ) |
| 96 | + } |
| 97 | + |
82 | 98 | // This is only used in prod, so dev uses `next dev` directly |
83 | 99 | netlifyConfig.redirects.push( |
84 | 100 | { from: `${basePath}/_next/static/*`, to: `/static/:splat`, status: 200 }, |
85 | 101 | { |
86 | 102 | from: `${basePath}/*`, |
87 | 103 | to: HANDLER_FUNCTION_PATH, |
88 | 104 | status: 200, |
89 | | - force: true, |
90 | 105 | conditions: { Cookie: ['__prerender_bypass', '__next_preview_data'] }, |
91 | 106 | }, |
92 | 107 | ...redirects.map((redirect) => ({ |
|
0 commit comments