svgr.config.js 1016 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. svgo: true,
  8. prettier: true,
  9. svgoConfig: {
  10. plugins: [{ removeViewBox: false }],
  11. },
  12. }
  13. const comment = '// THIS FILE WAS AUTOGENERATED BY SVGR. DO NOT MODIFY IT MANUALLY.\n'
  14. function componentTemplate({ template }, opts, { imports, componentName, jsx }) {
  15. const plugins = ['jsx']
  16. if (opts.typescript) {
  17. plugins.push('typescript')
  18. }
  19. const typeScriptTpl = template.smart({ plugins })
  20. return typeScriptTpl.ast`
  21. ${comment}
  22. ${imports}
  23. export const ${componentName} = (props: React.SVGProps<SVGSVGElement>) => ${jsx}
  24. `
  25. }
  26. function indexTemplate(filePaths) {
  27. const exportEntries = filePaths.map((filePath) => {
  28. const basename = path.basename(filePath, path.extname(filePath))
  29. return `export * from './${basename}'`
  30. })
  31. return comment + exportEntries.join('\n') + '\n'
  32. }