1 | /**
|
2 | * ref:
|
3 | * https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/webpack-overrides.js
|
4 | */
|
5 | import crypto from 'crypto';
|
6 |
|
7 | const macroCheck = new RegExp('[./]macro');
|
8 |
|
9 | export default function() {
|
10 | return {
|
11 | // This function transforms the Babel configuration on a per-file basis
|
12 | config(config, { source }) {
|
13 | // Babel Macros are notoriously hard to cache, so they shouldn't be
|
14 | // https://github.com/babel/babel/issues/8497
|
15 | // We naively detect macros using their package suffix and add a random token
|
16 | // to the caller, a valid option accepted by Babel, to compose a one-time
|
17 | // cacheIdentifier for the file. We cannot tune the loader options on a per
|
18 | // file basis.
|
19 | if (macroCheck.test(source)) {
|
20 | return Object.assign({}, config.options, {
|
21 | caller: Object.assign({}, config.options.caller, {
|
22 | craInvalidationToken: crypto.randomBytes(32).toString('hex'),
|
23 | }),
|
24 | });
|
25 | }
|
26 | return config.options;
|
27 | },
|
28 | };
|
29 | }
|