babel.config.js 1.5 KB

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