Is there a way to exclude specific pages from production build
See original GitHub issueI know this was discussed in #2332 but I have a slightly different use case which I’d like to share.
Feature request
Ignore certain pages under pages/ at build time.
Is your feature request related to a problem? Please describe.
I’m using the same MDX pages (content) in two projects. One handles MDX at runtime and let’s me catch malformed MDX/JSX at runtime. The other project uses the MDX files directly at buildtime, but now it fails on a page I was using to demonstrate error handling.
Describe the solution you’d like
Could there be a next.config.js
key, like pageExtensions
but instead to prevent certain pages (by regex or simple array) from being built? Maybe ignorePages
?
Describe alternatives you’ve considered
Neither the HOC approach nor the 404 trick would help in the case of (known) malformed pages.
Additional context
Note that I’m not looking to put otherwise useful files under pages/
but I want to handle the case of known malformed files.
Back to my two-project example, you could think of one as the Admin and the other as the Public site. Files from Admin are automatically copied to Public using dat, but it would apply to any kind of sync.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:10 (2 by maintainers)
I use
getStaticProps
to exclude static pages from builds. For example, in my pages directory, I have a folder called admin. Every page under that directory has the belowgetStaticProps
. This can also work to exclude a single page in a directory.During the build and export, the admin directory is skipped. I do not know if this will work for SSR pages.
wrote up how this could be added to Next.js in this discussion: https://github.com/vercel/next.js/discussions/29514 please chime in with feedback/support!