babel.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. const packageConfig = require('./package');
  20. module.exports = {
  21. sourceMaps: true,
  22. sourceType: 'module',
  23. retainLines: true,
  24. presets: [
  25. [
  26. '@babel/preset-env',
  27. {
  28. useBuiltIns: 'usage',
  29. corejs: 3,
  30. loose: true,
  31. modules: false,
  32. shippedProposals: true,
  33. targets: packageConfig.browserslist,
  34. },
  35. ],
  36. [
  37. '@babel/preset-react',
  38. {
  39. development: process.env.BABEL_ENV === 'development',
  40. runtime: 'automatic',
  41. },
  42. ],
  43. '@babel/preset-typescript',
  44. ],
  45. plugins: [
  46. 'lodash',
  47. '@babel/plugin-syntax-dynamic-import',
  48. '@babel/plugin-transform-export-namespace-from',
  49. ['@babel/plugin-transform-class-properties', { loose: true }],
  50. ['@babel/plugin-transform-optional-chaining', { loose: true }],
  51. ['@babel/plugin-transform-private-methods', { loose: true }],
  52. ['@babel/plugin-transform-nullish-coalescing-operator', { loose: true }],
  53. ['@babel/plugin-transform-runtime', { corejs: 3 }],
  54. // only used in packages/superset-ui-core/src/chart/components/reactify.tsx
  55. ['babel-plugin-typescript-to-proptypes', { loose: true }],
  56. 'react-hot-loader/babel',
  57. [
  58. '@emotion/babel-plugin',
  59. {
  60. autoLabel: 'dev-only',
  61. labelFormat: '[local]',
  62. },
  63. ],
  64. ],
  65. env: {
  66. // Setup a different config for tests as they run in node instead of a browser
  67. test: {
  68. presets: [
  69. [
  70. '@babel/preset-env',
  71. {
  72. useBuiltIns: 'usage',
  73. corejs: 3,
  74. loose: true,
  75. shippedProposals: true,
  76. modules: 'auto',
  77. targets: { node: 'current' },
  78. },
  79. ],
  80. [
  81. '@babel/preset-react',
  82. {
  83. development: process.env.BABEL_ENV === 'development',
  84. runtime: 'automatic',
  85. },
  86. ],
  87. '@babel/preset-typescript',
  88. ],
  89. plugins: [
  90. 'babel-plugin-dynamic-import-node',
  91. '@babel/plugin-transform-modules-commonjs',
  92. '@babel/plugin-transform-export-namespace-from',
  93. ],
  94. },
  95. // build instrumented code for testing code coverage with Cypress
  96. instrumented: {
  97. plugins: [
  98. [
  99. 'istanbul',
  100. {
  101. exclude: ['plugins/**/*', 'packages/**/*'],
  102. },
  103. ],
  104. ],
  105. },
  106. production: {
  107. plugins: [
  108. [
  109. 'babel-plugin-jsx-remove-data-test-id',
  110. {
  111. attributes: 'data-test',
  112. },
  113. ],
  114. ],
  115. },
  116. testableProduction: {
  117. plugins: [],
  118. },
  119. },
  120. overrides: [
  121. {
  122. test: './plugins/plugin-chart-handlebars/node_modules/just-handlebars-helpers/*',
  123. sourceType: 'unambiguous',
  124. },
  125. ],
  126. };