/ lib / modules / pipeline / babel-loader-overrides.js
babel-loader-overrides.js
 1  /**
 2   * This source code was adapted from:
 3   * https://github.com/facebook/create-react-app/blob/v2.0.4/packages/babel-preset-react-app/webpack-overrides.js
 4   *
 5   * Copyright (c) 2015-present, Facebook, Inc.
 6   *
 7   * The MIT license for this code may be found on GitHub:
 8   * https://github.com/facebook/create-react-app/blob/v2.0.4/packages/babel-preset-react-app/LICENSE
 9   */
10  
11  const crypto = require('crypto');
12  const macroCheck = new RegExp('[./]macro');
13  
14  module.exports = function () {
15    return {
16      config(config, {source}) {
17        // don't cache babel macros
18        // https://github.com/babel/babel/issues/8497
19        if (macroCheck.test(source)) {
20          return Object.assign({}, config.options, {
21            caller: Object.assign({}, config.options.caller, {
22              macroInvalidationToken: crypto.randomBytes(32).toString('hex')
23            })
24          });
25        }
26        return config.options;
27      }
28    };
29  };