babel.config.js 1.3 KB

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