Skip to content

Commit

Permalink
Switch back to babel-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Sep 27, 2018
1 parent 27ac52a commit c92efca
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 44 deletions.
27 changes: 24 additions & 3 deletions packages/babel-preset-react-app/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,28 @@
*/
'use strict';

const loader = require('babel-loader');
const overrides = require('./overrides');
const crypto = require('crypto');

module.exports = loader.custom(() => overrides);
module.exports = function() {
return {
// This function transforms the Babel configuration on a per-file basis
config(config, { source }) {
// Babel Macros are notoriously hard to cache, so they shouldn't be
// https://github.com/babel/babel/issues/8497
// We naively detect macros using their package suffix and insert a random
// caller name, a valid option accepted by Babel, to compose a one-time
// cacheIdentifier for the file. We cannot tune the loader options on a per
// file basis.
if (source.indexOf('.macro') !== -1 || source.indexOf('/macro') !== -1) {
return {
...config.options,
caller: {
name: 'babel-preset-react-app',
craInvalidationToken: crypto.randomBytes(32).toString('hex'),
},
};
}
return config.options;
},
};
};
32 changes: 0 additions & 32 deletions packages/babel-preset-react-app/overrides.js

This file was deleted.

3 changes: 1 addition & 2 deletions packages/babel-preset-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"dev.js",
"index.js",
"loader.js",
"overrides.js",
"prod.js",
"test.js"
],
Expand All @@ -31,7 +30,7 @@
"@babel/preset-flow": "7.0.0",
"@babel/preset-react": "7.0.0",
"@babel/runtime": "7.0.0",
"babel-loader": "8.0.2",
"babel-loader": "8.0.4",
"babel-plugin-macros": "2.4.2",
"babel-plugin-transform-dynamic-import": "2.1.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.18"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-error-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
"babel-loader": "8.0.2",
"babel-loader": "8.0.4",
"babel-preset-react-app": "^4.0.0",
"chalk": "^2.3.2",
"chokidar": "^2.0.2",
Expand Down
6 changes: 2 additions & 4 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,9 @@ module.exports = {
},
},
{
// We need to use our own loader until `babel-loader` supports
// customization
// https://github.com/babel/babel-loader/pull/687
loader: require.resolve('babel-preset-react-app/loader'),
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve('babel-preset-react-app/loader'),
// @remove-on-eject-begin
babelrc: false,
configFile: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ module.exports = {
// We need to use our own loader until `babel-loader` supports
// customization
// https://github.com/babel/babel-loader/pull/687
loader: require.resolve('babel-preset-react-app/loader'),
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve('babel-preset-react-app/loader'),
// @remove-on-eject-begin
babelrc: false,
configFile: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
"babel-loader": "8.0.2",
"babel-loader": "8.0.4",
"babel-plugin-named-asset-import": "^0.2.0",
"babel-preset-react-app": "^4.0.0",
"bfj": "6.1.1",
Expand Down

0 comments on commit c92efca

Please sign in to comment.