babel.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. break;
  51. }
  52. const config = {
  53. presets: [
  54. '@babel/preset-typescript',
  55. ['@babel/react', reactOptions],
  56. ['@babel/env', envOptions],
  57. ],
  58. plugins,
  59. overrides: [
  60. {
  61. test: /tesseract\.js/,
  62. presets: [
  63. ['@babel/env', { ...envOptions, modules: 'commonjs' }],
  64. ],
  65. },
  66. ],
  67. };
  68. return config;
  69. };