-
Notifications
You must be signed in to change notification settings - Fork 89
fix: publish from subdirectory #1756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
6b83c9a
to
2558855
Compare
@@ -25,14 +25,6 @@ import { | |||
const matchesMiddleware = (middleware: Array<string>, route: string): boolean => | |||
middleware.some((middlewarePath) => route.startsWith(middlewarePath)) | |||
|
|||
const generateHiddenPathRedirects = ({ basePath }: Pick<NextConfig, 'basePath'>): NetlifyConfig['redirects'] => | |||
HIDDEN_PATHS.map((path) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore, as these aren't published
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are/were HIDDEN_PATHS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were the files in .next
that we didn't want to be publicly-visible in the deploy, such as cache
, server
and various json files
@@ -66,21 +58,6 @@ const generateLocaleRedirects = ({ | |||
return redirects | |||
} | |||
|
|||
export const generateStaticRedirects = ({ | |||
netlifyConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to redirect, because the files are in the right place
|
||
if (i18n) { | ||
netlifyConfig.redirects.push({ from: `${basePath}/:locale/_next/static/*`, to: `/static/:splat`, status: 200 }) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems i18n still loads from /_next
in the root, so it's not needed
}): Promise<void> => { | ||
console.log('Moving static page files to serve from CDN...') | ||
const outputDir = join(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless') | ||
const outputDir = join(distDir, 'server') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have we removed serverless from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We force builds to use server
target anyway, and in Next 13 serverless
breaks the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @ascorbic! 🚀
Summary
Currently we expect Next.js to publish the
distDir
(i.e..next
). This is how we ascertain how to find the build files, particularlyrequired-server-files.json
. However most of the generated outputs are not created in the correct structure, so we need to copy or move them there as part of the build. This has worked fine so far, but has some important drawbacks. The main one is that it means the whole folder is uploaded as part of the deploy, even though most of it is not needed - and in fact needs 404 redirects to avoid making them publicly available. This hasn't been a major problem in the past (once the first deploy has been uploaded there aren't many extra files that need uploading). However Next 13 has started generating very large cache files that change on every build, which are now being uploaded every time.Since this plugin was created it is now possible to change the publish dir from within a build plugin. This gives us another option that retains the best of these worlds. We can use
.next
as the default publish dir, but during the build change it to a hidden.next/dist
dir, which then contains the actual files.Test plan
Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was published correctly.