swc.js 1.0 KB

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