| 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 | }; |