Skip to content
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

Is there a way to exclude specific pages from production build #8974

Closed
millette opened this issue Oct 5, 2019 · 10 comments
Closed

Is there a way to exclude specific pages from production build #8974

millette opened this issue Oct 5, 2019 · 10 comments

Comments

@millette
Copy link
Contributor

millette commented Oct 5, 2019

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.

@sideroad

This comment has been minimized.

@Timer
Copy link
Member

Timer commented Oct 16, 2019

This has been heavily debated in previous issues which can be found via search.

At present time, we're not exploring adding an option to remove specific pages from the production build.

tl;dr if they aren't pages, remove them from the pages directory.

You may be able to find more help for your unique use case on Spectrum.

@Timer Timer closed this as completed Oct 16, 2019
@Lpaydat
Copy link

Lpaydat commented Feb 19, 2020

I just pass by but wonder about this too since one of my page is .eslintrc.json (it contains the local rules so it is not possible to move it to another dir).

It also shows when running yarn next build as a page too.

If I try to access it, e.g. at http://localhost:3000/api/.eslintrc, it will render Internal Server Error on the screen and this log on the server-side.

TypeError: resolver is not a function
    at Object.apiResolver (/home/<name>/Workspace/<project>/node_modules/next/dist/next-server/server/api-utils.js:42:15)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async DevServer.handleApiRequest (/home/<name>/Workspace/<project>/node_modules/next/dist/next-server/server/next-server.js:446:9)
    at async Object.fn (/home/<name>/Workspace/<project>/node_modules/next/dist/next-server/server/next-server.js:367:37)
    at async Router.execute (/home/<name>/Workspace/<project>/node_modules/next/dist/next-server/server/router.js:42:32)
    at async DevServer.run (/home/<name>/Workspace/<project>/node_modules/next/dist/next-server/server/next-server.js:487:29)

Maybe this is not a big deal but it may be good if we can exclude the hidden pages from the production build.

Note: I tried pageExtensions to exclude .json files, it worked well in the past but after added multiple boilerplates to next.config.js it stops working for some reason.

@kud
Copy link

kud commented May 19, 2020

I'm in a case that it sounds legit to me that my component is in pages without being seen as a page itself:

image

@kud
Copy link

kud commented May 19, 2020

Workaround for the moment:

image

@jimisaacs
Copy link

jimisaacs commented Mar 17, 2021

In my case, I need to build the site twice for authenticated reasons. On one hand, there's unathed pages, and on another hand there's authed pages. It's extremely difficult to manage this with a single export without making them entirely different sites.

Though I haven't been able to figure out how to build the site twice, where there's a clean separation using different exportPathMap return values.

@jimisaacs
Copy link

jimisaacs commented Mar 17, 2021

Meaning, no matter what I do with exportPathMap or any other setting, knob, config value I've turned, the export always includes chunks, js, assets, etc. related to the pages that I did not actually export.

@mmmulani
Copy link

wrote up how this could be added to Next.js in this discussion: #29514 please chime in with feedback/support!

@skworden
Copy link

skworden commented Nov 2, 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: {} };
};

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants