I'm encountering a problem when set a custom directory in Next JS.
I know that by default, the pages directory should be in root or the src directory, but this option doesn't suit me because I can't hide all the frontend files in one directory.
Instead i want to do it this way:
src
├── frontend
│ ├── pages
│ │ ├── index.tsx
│ │ ├── firstPage.tsx
│ │ ├── ...
│ │ components
│ │ ├── ...
├── backend
│ ├── ...
However Next JS doesn't allow me to do this and I don't understand why, I've tried looking for possibilities for this, e.g:
"scripts": {
"dev": "next ./src/frontend",
},
This works, but it's still not what I need. With this approach, next creates tsconfig, .next, etc directly in the frontend directory, which looks weird, I would like to keep the configuration files in the root directory.
It seems that for some reason I can't have pages directory inside frontend directory, but I can't figure out what this has to do with. If this is really the case could you tell me why?
Unfortunately, it seems Next.js officially supports only ./pages or ./src/pages directories. Tim explains his point of view over this decision in his comment in one of many issues requesting this option on Github see. More can be found also here and here.
However, you might want to check out this discussion, as Daniel's fork has option to look for pages in additiona directories.