Skip to content

Commit

Permalink
Added bundler property to babel caller (#558)
Browse files Browse the repository at this point in the history
Summary:
**Summary**

`name` is set to `babel-loader` in Webpack but certain tools use custom babel loaders which makes the `name` field an unpredictable property for detecting what bundler is being used.

Adding a bundler property to every loader will help make this more distinguishable.

Expo currently does this in the `expo/webpack-config` ([here](https://github.com/expo/expo-cli/blob/098b38a37a4271c8401a20e4a65340b01485adf2/packages/webpack-config/src/loaders/createBabelLoader.ts#L206-L207)) as a way of configuring the babel preset to tree-shake unused `react-native-web` code.

We'd like to move away from using `babel-loader` in favor of using this new `bundler` property so more free form configurations like "Metro + react-native-web" can be easily configurable expo/expo#8170
Pull Request resolved: #558

Reviewed By: motiz88

Differential Revision: D21593374

Pulled By: cpojer

fbshipit-source-id: 287aafcfea70d7fe61d69e3a202b7f05eac1699d
  • Loading branch information
EvanBacon authored and facebook-github-bot committed May 18, 2020
1 parent 97b5121 commit cd8c834
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/metro-babel-transformer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function transform({filename, options, plugins, src}: BabelTransformerArgs) {

try {
const babelConfig = {
caller: {name: 'metro', platform: options.platform},
caller: {name: 'metro', bundler: 'metro', platform: options.platform},
ast: true,
babelrc: options.enableBabelRCLookup,
code: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-react-native-babel-transformer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function transform({filename, options, src, plugins}: BabelTransformerArgs) {
// ES modules require sourceType='module' but OSS may not always want that
sourceType: 'unambiguous',
...buildBabelConfig(filename, options, plugins),
caller: {name: 'metro', platform: options.platform},
caller: {name: 'metro', bundler: 'metro', platform: options.platform},
ast: true,
};
const sourceAst = parseSync(src, babelConfig);
Expand Down

0 comments on commit cd8c834

Please sign in to comment.