1
0

svgr.config.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // eslint-disable-next-line @typescript-eslint/no-var-requires
  2. const path = require('path')
  3. module.exports = {
  4. template: componentTemplate,
  5. indexTemplate: indexTemplate,
  6. typescript: true,
  7. memo: true,
  8. prettier: true,
  9. jsxRuntime: 'automatic',
  10. svgoConfig: {
  11. plugins: [
  12. {
  13. name: 'preset-default',
  14. params: {
  15. overrides: {
  16. removeViewBox: false,
  17. cleanupIDs: false, // Figma already assigns unique ID for every SVG. With this option enabled, the IDs are no longer globally unique
  18. },
  19. },
  20. },
  21. ],
  22. },
  23. }
  24. const comment = '// THIS FILE WAS AUTOGENERATED BY SVGR. DO NOT MODIFY IT MANUALLY'
  25. function componentTemplate(variables, { tpl }) {
  26. return tpl`
  27. ${comment}
  28. ${variables.imports}
  29. ${variables.interfaces}
  30. const ${variables.componentName} = (${variables.props}) => (
  31. ${variables.jsx}
  32. )
  33. const Memo = memo(${variables.componentName})
  34. export { Memo as ${variables.componentName} }
  35. `
  36. }
  37. function indexTemplate(filePaths) {
  38. const exportEntries = filePaths.map((filePath) => {
  39. const basename = path.basename(filePath, path.extname(filePath))
  40. return `export * from './${basename}'`
  41. })
  42. return comment + '\n' + exportEntries.join('\n') + '\n'
  43. }