Skip to content

Improve next.config.js readability and robustness with clearer path resolution and comments #39404

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
import fs from 'fs'
import path from 'path'

import frontmatter from 'gray-matter'
// Replace imports with hardcoded values
const ROOT = process.env.ROOT || '.'

// Resolve root directory explicitly to avoid ambiguity
const ROOT = process.env.ROOT ?? path.resolve(process.cwd())

// Hard-coded language keys to avoid TypeScript import in config file
const languageKeys = ['en', 'es', 'ja', 'pt', 'zh', 'ru', 'fr', 'ko', 'de']

// Read homepage frontmatter to get product IDs
const homepage = path.posix.join(ROOT, 'content/index.md')
const { data } = frontmatter(fs.readFileSync(homepage, 'utf8'))
const productIds = data.children

const DEFAULT_VERSION = 'free-pro-team@latest'

export default {
// speed up production `next build` by ignoring typechecking during that step of build.
// type-checking still occurs in the Dockerfile build
// Speed up production `next build` by ignoring typechecking during build
// Type-checking still occurs in Dockerfile build step
typescript: {
ignoreBuildErrors: true,
},

// Prevent ESLint errors from breaking builds
eslint: {
ignoreDuringBuilds: true,
},

i18n: {
locales: languageKeys,
defaultLocale: 'en',
},

sassOptions: {
quietDeps: true,
// Silence specific deprecation warnings from sass compiler
silenceDeprecations: [
'legacy-js-api',
'import',
Expand All @@ -35,40 +43,33 @@ export default {
'mixed-decls',
],
},

async rewrites() {
const DEFAULT_VERSION = 'free-pro-team@latest'
return productIds.map((productId) => {
return {
source: `/${productId}/:path*`,
destination: `/${DEFAULT_VERSION}/${productId}/:path*`,
}
})
return productIds.map((productId) => ({
source: `/${productId}/:path*`,
destination: `/${DEFAULT_VERSION}/${productId}/:path*`,
}))
},
webpack: (config) => {

webpack(config) {
config.experiments = config.experiments || {}
config.experiments.topLevelAwait = true
// Prevent bundling node 'fs' module on client-side
config.resolve.fallback = { fs: false }
return config
},

// https://nextjs.org/docs/api-reference/next.config.js/compression
// Disable compression (optional, depends on your infrastructure)
compress: false,

// ETags break stale content serving from the CDN. When a response has
// an ETag, the CDN attempts to revalidate the content in the background.
// This causes problems with serving stale content, since upon revalidating
// the CDN marks the cached content as "fresh".
// Disable ETags to avoid stale content issues with CDN
generateEtags: false,

experimental: {
// The output of our getServerSideProps() return large chunks of
// data because it contains our rendered Markdown.
// The default, for a "Large Page Data" warning is 128KB
// but many of our pages are much larger.
// The warning is: https://nextjs.org/docs/messages/large-page-data
largePageDataBytes: 1024 * 1024, // 1 MB
// Increase large page data warning threshold to 1MB
largePageDataBytes: 1024 * 1024,

// This makes it so that going Back will scroll to the previous position
// Enable scroll restoration when navigating back/forward
scrollRestoration: true,
},

Expand Down
Loading