babel.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* eslint global-require: off, import/no-extraneous-dependencies: off */
  2. const developmentEnvironments = ['development', 'test'];
  3. const developmentPlugins = [require('@babel/plugin-transform-runtime')];
  4. const productionPlugins = [
  5. require('babel-plugin-dev-expression'),
  6. // babel-preset-react-optimize
  7. require('@babel/plugin-transform-react-constant-elements'),
  8. require('@babel/plugin-transform-react-inline-elements'),
  9. require('babel-plugin-transform-react-remove-prop-types'),
  10. ];
  11. module.exports = (api) => {
  12. // See docs about api at https://babeljs.io/docs/en/config-files#apicache
  13. const development = api.env(developmentEnvironments);
  14. return {
  15. presets: [
  16. // @babel/preset-env will automatically target our browserslist targets
  17. require('@babel/preset-env'),
  18. require('@babel/preset-typescript'),
  19. [require('@babel/preset-react'), { development }],
  20. ],
  21. plugins: [
  22. // Stage 0
  23. require('@babel/plugin-proposal-function-bind'),
  24. // Stage 1
  25. require('@babel/plugin-proposal-export-default-from'),
  26. require('@babel/plugin-proposal-logical-assignment-operators'),
  27. [require('@babel/plugin-proposal-optional-chaining'), { loose: false }],
  28. [
  29. require('@babel/plugin-proposal-pipeline-operator'),
  30. { proposal: 'minimal' },
  31. ],
  32. [
  33. require('@babel/plugin-proposal-nullish-coalescing-operator'),
  34. { loose: false },
  35. ],
  36. require('@babel/plugin-proposal-do-expressions'),
  37. // Stage 2
  38. [require('@babel/plugin-proposal-decorators'), { legacy: true }],
  39. require('@babel/plugin-proposal-function-sent'),
  40. require('@babel/plugin-proposal-export-namespace-from'),
  41. require('@babel/plugin-proposal-numeric-separator'),
  42. require('@babel/plugin-proposal-throw-expressions'),
  43. // Stage 3
  44. require('@babel/plugin-syntax-dynamic-import'),
  45. require('@babel/plugin-syntax-import-meta'),
  46. [require('@babel/plugin-proposal-class-properties'), { loose: true }],
  47. require('@babel/plugin-proposal-json-strings'),
  48. ...(development ? developmentPlugins : productionPlugins),
  49. ],
  50. };
  51. };