|
| 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 | +module.exports = { |
| 12 | + // This function transforms the Babel configuration on a per-file basis |
| 13 | + config(config, { source }) { |
| 14 | + // Babel Macros are notoriously hard to cache, so they shouldn't be |
| 15 | + // https://github.com/babel/babel/issues/8497 |
| 16 | + // We naively detect macros using their package suffix and insert a random |
| 17 | + // caller name, a valid option accepted by Babel, to compose a one-time |
| 18 | + // cacheIdentifier for the file. We cannot tune the loader options on a per |
| 19 | + // file basis. |
| 20 | + if (source.indexOf('.macro') !== -1 || source.indexOf('/macro') !== -1) { |
| 21 | + return { |
| 22 | + ...config.options, |
| 23 | + caller: { |
| 24 | + name: `babel-preset-react-app:${crypto |
| 25 | + .randomBytes(32) |
| 26 | + .toString('hex')}`, |
| 27 | + }, |
| 28 | + }; |
| 29 | + } |
| 30 | + return config.options; |
| 31 | + }, |
| 32 | +}; |
0 commit comments