babel.config.js 1.5 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. loose: true,
  9. modules: false,
  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 config = {
  19. presets: [
  20. '@babel/preset-typescript',
  21. ['@babel/react', reactOptions],
  22. ['@babel/env', envOptions],
  23. ],
  24. plugins: [
  25. ['formatjs'],
  26. 'preval',
  27. ],
  28. overrides: [
  29. {
  30. test: /tesseract\.js/,
  31. presets: [
  32. ['@babel/env', { ...envOptions, modules: 'commonjs' }],
  33. ],
  34. },
  35. ],
  36. };
  37. switch (env) {
  38. case 'production':
  39. config.plugins.push(...[
  40. 'lodash',
  41. [
  42. 'transform-react-remove-prop-types',
  43. {
  44. mode: 'remove',
  45. removeImport: true,
  46. additionalLibraries: [
  47. 'react-immutable-proptypes',
  48. ],
  49. },
  50. ],
  51. '@babel/transform-react-inline-elements',
  52. [
  53. '@babel/transform-runtime',
  54. {
  55. helpers: true,
  56. regenerator: false,
  57. useESModules: true,
  58. },
  59. ],
  60. ]);
  61. break;
  62. case 'development':
  63. reactOptions.development = true;
  64. envOptions.debug = true;
  65. break;
  66. case 'test':
  67. envOptions.modules = 'commonjs';
  68. break;
  69. }
  70. return config;
  71. };