-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(babel-preset-gatsby-package): add conditional compilation plugin #32687
Merged
Conversation
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
eca0fd3
to
b465ec5
Compare
wardpeet
commented
Aug 5, 2021
Comment on lines
+120
to
+121
"check-repo-fields": "node scripts/check-repo-fields.js", | ||
"check-versions": "node scripts/check-versions.js", |
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.
These are not necessary anymore, else I had to change a few things in babelrc
wardpeet
commented
Aug 5, 2021
@@ -15,6 +15,7 @@ | |||
"resolveJsonModule": true, | |||
"esModuleInterop": true, | |||
"jsx": "preserve", | |||
"typeRoots": ["./types", "**/node_modules/@types", "node_modules/@types"], |
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.
This is necessary to find the global CFLAGS types in the monorepo
pieh
reviewed
Aug 5, 2021
pieh
previously approved these changes
Aug 5, 2021
pieh
approved these changes
Aug 5, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
topic: core
Relates to Gatsby's core (e.g. page loading, reporter, state machine)
type: feature or enhancement
Issue that is not a bug and requests the addition of a new feature or enhancement.
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.
Description
Added an extra feature to babel-preset-gatsby-package to enable Conditional compilation. It's a fancy word to add if cases that are evaluated at build time. In the long run, we'll have a real bundle that would also compile the code path away.
To enable the features you have to set availableCompilerFlags as an option in the babel-preset-gatsby-package.
In code you can set it:
These flags are parsed from
process.env.COMPILER_OPTIONS
, the syntax used isGATSBY_MAJOR=4
. If you need multiple variables, you have to comma separate themGATSBY_MAJOR=4,ANOTHER=hello
.Why not use comments?
I thought of using comments instead which would allow us to remove code blocks using babel but these bits would not be caught by eslint or typescript and the babel transformer would become more complex. We can do this in a further iteration if we see more benefits around this.
Related Issues
[ch35493]