Open laozhu opened 2 years ago
@laozhu Did you find a solution for this?
@thedaviddias I ended up writing the type definitions manually.
declare module '@scope-name/icons' {
type ReactComponent = React.FC<
React.SVGProps<SVGSVGElement> & {
title?: string | undefined;
}
>;
const Sms: ReactComponent;
}
tsup.config.ts
import svgrPlugin from 'esbuild-plugin-svgr';
import { defineConfig } from 'tsup';
export default defineConfig({
...,
esbuildPlugins: [svgrPlugin({ template })],
});
function template(variables, { tpl }) {
return tpl`
${variables.imports};
${variables.interfaces};
const ${variables.componentName} = (${variables.props}) => (
${variables.jsx}
);
${variables.exports};
export const ReactComponent = ${variables.componentName};
`;
}
it works for me
SVG was compiled successfully, by using
import svgrPlugin from 'esbuild-plugin-svgr';
import { defineConfig } from 'tsup';
export default defineConfig({
esbuildPlugins: [svgrPlugin()],
});
First I have a svg file
Then I use svgr to import it as react component
I use vite and vite-plugin-svgr to bundle the icon libraries (success)
Try to generate .d.ts files with below cli (failed)
If I want to use tsup for dts only, can I have a method to avoid this error?
Upvote & Fund