babel.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. module.exports = (api) => {
  2. const env = api.env();
  3. const reactOptions = {
  4. development: false,
  5. };
  6. const envOptions = {
  7. loose: true,
  8. modules: false,
  9. debug: false,
  10. };
  11. const config = {
  12. presets: [
  13. ['@babel/react', reactOptions],
  14. ['@babel/env', envOptions],
  15. ],
  16. plugins: [
  17. ['@babel/proposal-decorators', { legacy: true }],
  18. '@babel/proposal-class-properties',
  19. ['react-intl', { messagesDir: './build/messages' }],
  20. 'preval',
  21. ],
  22. overrides: [
  23. {
  24. test: /tesseract\.js/,
  25. presets: [
  26. ['@babel/env', { ...envOptions, modules: 'commonjs' }],
  27. ],
  28. },
  29. ],
  30. };
  31. switch (env) {
  32. case 'production':
  33. config.plugins.push(...[
  34. 'lodash',
  35. [
  36. 'transform-react-remove-prop-types',
  37. {
  38. mode: 'remove',
  39. removeImport: true,
  40. additionalLibraries: [
  41. 'react-immutable-proptypes',
  42. ],
  43. },
  44. ],
  45. '@babel/transform-react-inline-elements',
  46. [
  47. '@babel/transform-runtime',
  48. {
  49. helpers: true,
  50. regenerator: false,
  51. useESModules: true,
  52. },
  53. ],
  54. ]);
  55. break;
  56. case 'development':
  57. reactOptions.development = true;
  58. envOptions.debug = true;
  59. break;
  60. case 'test':
  61. envOptions.modules = 'commonjs';
  62. break;
  63. }
  64. return config;
  65. };