Next.js: Apparently unable to use next export with static files like robots.txt

Created on 11 Sep 2017  路  5Comments  路  Source: vercel/next.js

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior


next export should support static files like robots.txt.

Current Behavior


next export does not apparently support static files like robots.txt. Or if it does, it's a well hidden feature.

Context


I'd like to use next.js for creating a static site (built using next export, with no custom server for routing). This static site needs the usual static URLs, such as /robots.txt.

I can't add a custom server.

How do I implement robots.txt with next export?

  • I can't use a custom server.js to redirect /robots.txt to /static/robots.txt, because next export doesn't use server.js.
  • I can't specify { '/robots.txt': { page: '/static/robots.txt' }} in the next.config.js function exportPathMap used by next export, because this mapping applies only to pages inside the pages directory.
  • I can't create a pages/robots.txt.js that uses getInitialProps and res.write (as described in https://github.com/zeit/next.js/issues/751#issuecomment-272292486) to output plain text, because res isn't available during next export.

My only remaining ideas are to fork next.js, or to do extra steps after the next.js build process to add the necessary static files.

Are there any better ways?

Most helpful comment

@timneutkens If this is the project's recommended workaround, then to help others with the same issue you should add it to the documentation. It's hard to find otherwise.

All 5 comments

I haven't found a better way so after next export I just run cp static/robots.txt out/robots.txt.

@gragland simple and elegant solution!

@timneutkens Did you close this because next.js now supports this feature? Or for some other reason?

@avaragado cause it's stale and a solution was given 馃憤 Going through all (250) issues.

@timneutkens If this is the project's recommended workaround, then to help others with the same issue you should add it to the documentation. It's hard to find otherwise.

Was this page helpful?
0 / 5 - 0 ratings