next.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Names this build, so a tab left open across a deploy can tell it is stale
  2. // (see components/update-on-return.tsx).
  3. const SITE_BUILD =
  4. process.env.VERCEL_GIT_COMMIT_SHA || `local-${Date.now().toString(36)}`;
  5. /** @type {import('next').NextConfig} */
  6. const nextConfig = {
  7. poweredByHeader: false,
  8. env: { SITE_BUILD },
  9. experimental: {
  10. // Ship the (small) stylesheet inline so first paint never waits on a CSS request.
  11. inlineCss: true,
  12. },
  13. images: {
  14. formats: ["image/avif", "image/webp"],
  15. minimumCacheTTL: 60 * 60 * 24 * 7,
  16. remotePatterns: [
  17. {
  18. protocol: "https",
  19. hostname: "firebasestorage.googleapis.com",
  20. },
  21. {
  22. protocol: "https",
  23. hostname: "www.notion.so",
  24. },
  25. // Blog covers linked straight from their source (see coverImageUrl).
  26. {
  27. protocol: "https",
  28. hostname: "upload.wikimedia.org",
  29. },
  30. {
  31. protocol: "https",
  32. hostname: "images.unsplash.com",
  33. },
  34. ],
  35. },
  36. // Pages live under app/[lang]. English keeps the bare URLs it always had
  37. // (/blog is served from /en/blog), Chinese lives under /zh, and an /en URL
  38. // redirects to its bare form so each page has one address.
  39. async redirects() {
  40. return [
  41. { source: "/en", destination: "/", permanent: true },
  42. { source: "/en/:path*", destination: "/:path*", permanent: true },
  43. ];
  44. },
  45. async rewrites() {
  46. return {
  47. // After files: public files, API routes and metadata routes match first.
  48. afterFiles: [
  49. { source: "/", destination: "/en" },
  50. {
  51. source: "/:path((?!zh(?:/|$)|en(?:/|$)|_next/|api/).*)",
  52. destination: "/en/:path",
  53. },
  54. ],
  55. };
  56. },
  57. async headers() {
  58. const cached = [
  59. {
  60. key: "Cache-Control",
  61. value: "public, max-age=86400, stale-while-revalidate=604800",
  62. },
  63. ];
  64. return [
  65. { source: "/data/:path*", headers: cached },
  66. { source: "/emoji/:path*", headers: cached },
  67. { source: "/mini.:ext", headers: cached },
  68. ];
  69. },
  70. };
  71. module.exports = nextConfig;