preprocessor.js 920 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Copyright (c) 2013-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 babel = require('@babel/core');
  9. const createCacheKeyFunction = require('./createCacheKeyFunction');
  10. const path = require('path');
  11. module.exports = {
  12. process(src, filename) {
  13. const options = {
  14. presets: [
  15. require('babel-preset-fbjs'),
  16. ],
  17. filename: filename,
  18. retainLines: true,
  19. };
  20. return babel.transform(src, options).code;
  21. },
  22. // Generate a cache key that is based on the contents of this file and the
  23. // fbjs preset package.json (used as a proxy for determining if the preset has
  24. // changed configuration at all).
  25. getCacheKey: createCacheKeyFunction([
  26. __filename,
  27. path.join(path.dirname(require.resolve('babel-preset-fbjs')), 'package.json')
  28. ]),
  29. };