svgr-icons.config.js 954 B

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