forked from Joystream/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvgr.config.js
38 lines (32 loc) · 1.02 KB
/
svgr.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path')
module.exports = {
template: componentTemplate,
indexTemplate: indexTemplate,
typescript: true,
svgo: true,
prettier: true,
svgoConfig: {
plugins: [{ removeViewBox: false }],
},
}
const comment = '// THIS FILE WAS AUTOGENERATED BY SVGR. DO NOT MODIFY IT MANUALLY'
function componentTemplate({ template }, opts, { imports, componentName, jsx }) {
const plugins = ['jsx']
if (opts.typescript) {
plugins.push('typescript')
}
const typeScriptTpl = template.smart({ plugins, preserveComments: true })
return typeScriptTpl.ast`
${comment}
${imports}
export const ${componentName} = (props: React.SVGProps<SVGSVGElement>) => ${jsx}
`
}
function indexTemplate(filePaths) {
const exportEntries = filePaths.map((filePath) => {
const basename = path.basename(filePath, path.extname(filePath))
return `export * from './${basename}'`
})
return comment + '\n' + exportEntries.join('\n') + '\n'
}