Next.js: Can we please have official support for putting everything in a src directory?

Created on 18 Aug 2019  Â·  4Comments  Â·  Source: vercel/next.js

This feature has been requested for years (e.g., https://github.com/zeit/next.js/issues/4789).

We've had workarounds, but now with things like official TS support it's no longer possible because Next assumes so much of our project structure. E.g., we can run "next ./src" but it assumes our tsconfig.json should be under src, too.

Putting everything in a src dir is such a common project structure. It's used by CRA and just about every React starter kit.

Our components dir is on the same level as dist, .babelrc, tsconfig.json, node_modules, pages, next.config.js, static, etc. It's so disorganized!

All we would like is a srcDir option. Why is there so much opposition from the Next team on this?

Most helpful comment

Going to close this as this is not following the issue template nor is it an RFC. I'm really not sure why you completely ignored the issue template.

I replied here yesterday that we'll soon add support for src: https://github.com/zeit/next.js/issues/4315#issuecomment-522263598

We'll post a RFC soon.

All 4 comments

Why is there so much opposite from the Next team on this

I'd guess because a lot of functionality and optimizations in next.js are build around having the pages inside the pages directory.

On a side note - i was upvoting the original issue and just removed my vote.

After using next.js for a while I learned to bend my mental model to see pages folder as routes api only (i guess routes would have been a better name, but no need to change it).
As soon as you want things like page in page modals https://reacttraining.com/react-router/web/example/modal-gallery with next having actual react component code in pages is no longer feasible and you might want to start a reexport pattern like described in the linked issue.

We currently use this structure in a rather big app and developers tend to like(or at least not hate) it.

- index
- auth
-- login
- api
-- graphql
src
- frontend
-- pages
--- Home
--- auth
---- Login
- backend
-- gql
-- models

I'd love to see https://github.com/zeit/next.js/issues/7779 to land as we currently still rely on relative import paths.

I'd guess because a lot of functionality and optimizations in next.js are build around having the pages inside the pages directory.

I fully understand this, but allowing the directory to be ./src/pages instead of ./pages shouldn't affect any of these optimizations — the pages dir is still treated as a routes api.

Going to close this as this is not following the issue template nor is it an RFC. I'm really not sure why you completely ignored the issue template.

I replied here yesterday that we'll soon add support for src: https://github.com/zeit/next.js/issues/4315#issuecomment-522263598

We'll post a RFC soon.

Was this page helpful?
0 / 5 - 0 ratings