swc.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {srcPath, require} from './paths.ts';
  2. import browserslist from 'browserslist';
  3. const isProduction = process.env.NODE_ENV === 'production';
  4. export default function(isTs: boolean) {
  5. return {
  6. loader: require.resolve('swc-loader'),
  7. test: isTs ? /.tsx?$/ : /.(js|jsx|mjs)$/,
  8. include: srcPath,
  9. options: {
  10. jsc: {
  11. externalHelpers: true,
  12. parser: {
  13. syntax: isTs ? 'typescript' : 'ecmascript',
  14. [isTs ? 'tsx' : 'jsx']: true,
  15. decorators: true,
  16. dynamicImport: true,
  17. },
  18. transform: {
  19. react: {
  20. refresh: !isProduction,
  21. runtime: 'automatic',
  22. },
  23. decoratorVersion: '2022-03',
  24. },
  25. experimental: {
  26. plugins: [
  27. isProduction && [
  28. require.resolve('swc-plugin-react-remove-properties'),
  29. {
  30. properties: ['data-testid'],
  31. },
  32. ],
  33. ].filter(Boolean),
  34. },
  35. },
  36. env: {
  37. targets: browserslist(),
  38. mode: 'usage',
  39. coreJs: '3.30.1',
  40. },
  41. },
  42. };
  43. }