webpack-overrides.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. const crypto = require('crypto');
  9. const macroCheck = new RegExp('[./]macro');
  10. module.exports = function () {
  11. return {
  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 add a random token
  17. // to the caller, 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 (macroCheck.test(source)) {
  21. return Object.assign({}, config.options, {
  22. caller: Object.assign({}, config.options.caller, {
  23. craInvalidationToken: crypto.randomBytes(32).toString('hex'),
  24. }),
  25. });
  26. }
  27. return config.options;
  28. },
  29. };
  30. };