babel.config.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. module.exports = (api) => {
  2. const env = api.env();
  3. const reactOptions = {
  4. development: false,
  5. runtime: 'automatic',
  6. };
  7. const envOptions = {
  8. useBuiltIns: "usage",
  9. corejs: { version: "3.30" },
  10. debug: false,
  11. include: [
  12. 'transform-numeric-separator',
  13. 'transform-optional-chaining',
  14. 'transform-nullish-coalescing-operator',
  15. 'transform-class-properties',
  16. ],
  17. };
  18. const plugins = [
  19. ['formatjs'],
  20. 'preval',
  21. ];
  22. switch (env) {
  23. case 'production':
  24. plugins.push(...[
  25. 'lodash',
  26. [
  27. 'transform-react-remove-prop-types',
  28. {
  29. mode: 'remove',
  30. removeImport: true,
  31. additionalLibraries: [
  32. 'react-immutable-proptypes',
  33. ],
  34. },
  35. ],
  36. '@babel/transform-react-inline-elements',
  37. [
  38. '@babel/transform-runtime',
  39. {
  40. helpers: true,
  41. regenerator: false,
  42. useESModules: true,
  43. },
  44. ],
  45. ]);
  46. break;
  47. case 'development':
  48. reactOptions.development = true;
  49. envOptions.debug = true;
  50. // We need Babel to not inject polyfills in dev, as this breaks `preval` files
  51. envOptions.useBuiltIns = false;
  52. envOptions.corejs = undefined;
  53. break;
  54. }
  55. const config = {
  56. presets: [
  57. '@babel/preset-typescript',
  58. ['@babel/react', reactOptions],
  59. ['@babel/env', envOptions],
  60. ],
  61. plugins,
  62. overrides: [
  63. {
  64. test: [/tesseract\.js/, /fuzzysort\.js/],
  65. presets: [
  66. ['@babel/env', { ...envOptions, modules: 'commonjs' }],
  67. ],
  68. },
  69. ],
  70. };
  71. return config;
  72. };