Skip to content

Commit 39c73ce

Browse files
iansuTimer
authored andcommitted
Switch back to babel-loader (facebook#5143)
* Switch back to babel-loader * Preserve existing caller options. Use Object.assign instead of object spread. * Updated filename in package.json * Update comment about cache identifier * Update macro check to use a regex * Move macro check regex out of function
1 parent af61071 commit 39c73ce

File tree

8 files changed

+45
-54
lines changed

8 files changed

+45
-54
lines changed

packages/babel-preset-react-app/loader.js

-12
This file was deleted.

packages/babel-preset-react-app/overrides.js

-32
This file was deleted.

packages/babel-preset-react-app/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"dependencies.js",
1313
"dev.js",
1414
"index.js",
15-
"loader.js",
16-
"overrides.js",
15+
"webpack-overrides.js",
1716
"prod.js",
1817
"test.js"
1918
],
@@ -31,7 +30,7 @@
3130
"@babel/preset-flow": "7.0.0",
3231
"@babel/preset-react": "7.0.0",
3332
"@babel/runtime": "7.0.0",
34-
"babel-loader": "8.0.2",
33+
"babel-loader": "8.0.4",
3534
"babel-plugin-macros": "2.4.2",
3635
"babel-plugin-transform-dynamic-import": "2.1.0",
3736
"babel-plugin-transform-react-remove-prop-types": "0.4.18"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
const crypto = require('crypto');
10+
11+
const macroCheck = new RegExp('[./]macro');
12+
13+
module.exports = function() {
14+
return {
15+
// This function transforms the Babel configuration on a per-file basis
16+
config(config, { source }) {
17+
// Babel Macros are notoriously hard to cache, so they shouldn't be
18+
// https://github.com/babel/babel/issues/8497
19+
// We naively detect macros using their package suffix and add a random token
20+
// to the caller, a valid option accepted by Babel, to compose a one-time
21+
// cacheIdentifier for the file. We cannot tune the loader options on a per
22+
// file basis.
23+
if (macroCheck.test(source)) {
24+
return Object.assign({}, config.options, {
25+
caller: Object.assign({}, config.options.caller, {
26+
craInvalidationToken: crypto.randomBytes(32).toString('hex'),
27+
}),
28+
});
29+
}
30+
return config.options;
31+
},
32+
};
33+
};

packages/react-error-overlay/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"babel-core": "7.0.0-bridge.0",
3737
"babel-eslint": "9.0.0",
3838
"babel-jest": "23.6.0",
39-
"babel-loader": "8.0.2",
39+
"babel-loader": "8.0.4",
4040
"babel-preset-react-app": "^4.0.0",
4141
"chalk": "^2.3.2",
4242
"chokidar": "^2.0.2",

packages/react-scripts/config/webpack.config.dev.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ module.exports = {
218218
},
219219
},
220220
{
221-
// We need to use our own loader until `babel-loader` supports
222-
// customization
223-
// https://github.com/babel/babel-loader/pull/687
224-
loader: require.resolve('babel-preset-react-app/loader'),
221+
loader: require.resolve('babel-loader'),
225222
options: {
223+
customize: require.resolve(
224+
'babel-preset-react-app/webpack-overrides'
225+
),
226226
// @remove-on-eject-begin
227227
babelrc: false,
228228
configFile: false,

packages/react-scripts/config/webpack.config.prod.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,11 @@ module.exports = {
272272
// We need to use our own loader until `babel-loader` supports
273273
// customization
274274
// https://github.com/babel/babel-loader/pull/687
275-
loader: require.resolve('babel-preset-react-app/loader'),
275+
loader: require.resolve('babel-loader'),
276276
options: {
277+
customize: require.resolve(
278+
'babel-preset-react-app/webpack-overrides'
279+
),
277280
// @remove-on-eject-begin
278281
babelrc: false,
279282
configFile: false,

packages/react-scripts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"babel-core": "7.0.0-bridge.0",
2727
"babel-eslint": "9.0.0",
2828
"babel-jest": "23.6.0",
29-
"babel-loader": "8.0.2",
29+
"babel-loader": "8.0.4",
3030
"babel-plugin-named-asset-import": "^0.2.0",
3131
"babel-preset-react-app": "^4.0.0",
3232
"bfj": "6.1.1",

0 commit comments

Comments
 (0)