swc.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. };
  12. module.exports = function(isTs) {
  13. return {
  14. loader: require.resolve('swc-loader'),
  15. test: isTs ? /.tsx?$/ : /.(js|jsx|mjs)$/,
  16. include: srcPath,
  17. options: {
  18. jsc: {
  19. parser: {
  20. syntax: isTs ? 'typescript' : 'ecmascript',
  21. [isTs ? 'tsx' : 'jsx']: true,
  22. ...swcParserOptions,
  23. },
  24. transform: {
  25. ...swcTransformOptions,
  26. },
  27. experimental: {
  28. plugins: [
  29. isProduction && [
  30. require.resolve('swc-plugin-react-remove-properties'),
  31. {
  32. properties: ['data-testid'],
  33. },
  34. ],
  35. ].filter(Boolean),
  36. },
  37. },
  38. env: {
  39. targets: browserslist(),
  40. mode: 'entry',
  41. },
  42. },
  43. };
  44. };