Define our own in-repo babel configuration #8624
Merged
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.
WHY are these changes introduced?
This PR replaces using
@shopify/babel-preset
with using the underlying presets directly.As part of this we simplify the plugins we use and lean more heavily on
@babel/preset-env
. As a result of this we no longer transpile numeric separators (1_000
), nullish coalescing operators (foo ?? 'bar'
) and optional chainingfoo?.bar
because our browserslist targets say that those features are all supported in the browsers that we target.This means that our build output now contains optional chaining et al.
A breaking change side-effect of this is that code that uses these features will no longer successfully parse in webpack4, as webpack4 uses an old version of acorn does not understand these syntaxes. Webpack5 uses a newer version of acorn that can read this just fine.
WHAT is this pull request doing?
Replace
@shopify/babel-config
with using@babel/preset-env
,@babel/preset-typescript
and@babel/preset-react
directly.This PR is split into two commits. The first replaces
@shopify/babel-preset
with inline config, with minimal changes. The second removes the forced compilation of the 5 plugins that were always forced to be enabled.How to 🎩
~/projects/polaris
directory and runcd package
,yarn
,yarn run turbo run build --filter='!polaris.shopify.com' --force
to produce a clean build~/src/github.com/Shopify/polaris
directory and runcd package
,yarn
,yarn run turbo run build --filter='!polaris.shopify.com' --force
to produce a buildtouch out.txt; for PACKAGENAME in $(ls -1 . | grep '^polaris-'); diff -ru ~/projects/polaris/$PACKAGENAME $PACKAGENAME -x '*.tsbuildinfo' -x '*.d.ts.map' -x'.turbo' -x '*.esnext' >> out.txt
to compare the build folder output. Note that the differences are as follows:void 0
. In all cases either the value is already implicitly undefined, or is assigned to a value shortly afterwards