-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
[core] Create shared Next.js baseline config #34259
Merged
oliviertassinari
merged 4 commits into
mui:master
from
oliviertassinari:create-baseline-next-config
Sep 17, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
let DEPLOY_ENV = 'development'; | ||
|
||
// Same as process.env.PULL_REQUEST_ID | ||
if (process.env.CONTEXT === 'deploy-preview') { | ||
DEPLOY_ENV = 'pull-request'; | ||
} | ||
|
||
if (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') { | ||
DEPLOY_ENV = 'production'; | ||
} | ||
|
||
if ( | ||
process.env.CONTEXT === 'branch-deploy' && | ||
(process.env.HEAD === 'master' || process.env.HEAD === 'next') | ||
) { | ||
DEPLOY_ENV = 'staging'; | ||
} | ||
|
||
process.env.DEPLOY_ENV = DEPLOY_ENV; | ||
|
||
function withDocsInfra(nextConfig) { | ||
return { | ||
trailingSlash: true, | ||
// Can be turned on when https://github.com/vercel/next.js/issues/24640 is fixed | ||
optimizeFonts: false, | ||
reactStrictMode: true, | ||
...nextConfig, | ||
env: { | ||
BUILD_ONLY_ENGLISH_LOCALE: true, // disable translations by default | ||
// production | staging | pull-request | development | ||
DEPLOY_ENV, | ||
...nextConfig.env, | ||
// https://docs.netlify.com/configure-builds/environment-variables/#git-metadata | ||
// reference ID (also known as “SHA” or “hash”) of the commit we’re building. | ||
COMMIT_REF: process.env.COMMIT_REF, | ||
// ID of the PR and the Deploy Preview it generated (for example, 1211) | ||
PULL_REQUEST_ID: process.env.REVIEW_ID, | ||
// This can be set manually in the .env to see the ads in dev mode. | ||
ENABLE_AD_IN_DEV_MODE: process.env.ENABLE_AD_IN_DEV_MODE, | ||
// URL representing the unique URL for an individual deploy, e.g. | ||
// https://5b243e66dd6a547b4fee73ae--petsof.netlify.app | ||
NETLIFY_DEPLOY_URL: process.env.DEPLOY_URL, | ||
// Name of the site, its Netlify subdomain; for example, material-ui-docs | ||
NETLIFY_SITE_NAME: process.env.SITE_NAME, | ||
}, | ||
experimental: { | ||
scrollRestoration: true, | ||
...nextConfig.experimental, | ||
}, | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
...nextConfig.eslint, | ||
}, | ||
typescript: { | ||
// Motivated by https://github.com/vercel/next.js/issues/7687 | ||
ignoreBuildErrors: true, | ||
...nextConfig.typescript, | ||
}, | ||
}; | ||
} | ||
|
||
module.exports = withDocsInfra; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to avoid passing
DEPLOY_ENV
to the application code entirely, and instead calculate these options centrally, in the next.js baseline config?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Janpot What's the value of this change? I understand the value of this indirection for secrets and constants used multiple times, but I don't get it for the rest. My goal in removing
docs/src/config
was to centralize the logic as much as possible in the same files.A side note. I would also be in favor of removing
docs/src/route
. The values feel no different from using the URLs directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not critical at all, it would mostly improve maintainability a bit and be more defensive code.
It creates a natural overview of which features are enabled for which environment. This is especially handy when a new environment has to be defined (e.g. new type of integration tests)
Injects the environment specific flags through the webpack define plugin. This prevents future maintainers from accidentally creating code that doesn't minify unused configuration away. e.g.
Avoids duplicating logic in case a certain flag is used in multiple places in the application. Or when the same flag is used between build time and run time
Yes, it's not critical neither. For me, the main advantage of such a file would be around static analyzability of where certain links are used. Especially when people start defining links like
/section-${sections.slug}
in one place and/section-intro
in others. Such constructs are hard to search for. If you use something like asectionLink('intro')
everywhere that could be easily listed using "find references" in vscodeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's minor, I'm more than fine for this PR to be merged as is