question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to exclude specific pages from production build

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
lifedupcommented, Nov 3, 2021

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 below getStaticProps. 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.

export const getStaticProps: GetStaticProps = async () => {
  if (process.env.NODE_ENV === 'production') {
    return { notFound: true };
  }
  return { props: {} };
};
2reactions
mmmulanicommented, Sep 30, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to exclude a specific folder inside pages from production ...
Currently while executing build command i got every pages inside the directories inside pages. Is it possible, in any way to exclude my...
Read more >
How to: Exclude Files from the Build - MSBuild | Microsoft Learn
Exclude a file or directory from the inputs for a build​​ To exclude an item from the item list, use the Exclude attribute....
Read more >
Excluding Page from Release Build in ASP.NET Project
One option is to edit your msbuild (*.csproj) file to conditionally exclude certain files based on the Solution Configuration (ie. Debug, Release, etc)....
Read more >
How to Exclude Specific Pages, Authors, and More from ...
The easiest way to exclude pages, authors, categories, taxonomies, tags, and more is by using the SearchWP plugin. It's the best WordPress ...
Read more >
Development-only pages in Next.js - DEV Community ‍ ‍
Build pages in Next.js that are only viewable in a development environment and are excluded from the production site.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found