I'm trying to import svg files using text loader.
tsup.config.ts
import { defineConfig } from 'tsup';
import { dependencies } from './package.json';
export default defineConfig({
entry: ['src/**/!(*.stories|*.test|*.d).(tsx|ts|jsx|js)'],
format: ['esm'],
target: 'esnext',
external: [
...Object.keys(dependencies),
],
loader: {
'.svg': 'text',
},
dts: true,
});
src/assets/icons.ts
export { default as ascending } from './icons/ascending.svg';
export { default as barGraph } from './icons/barGraph.svg';
export { default as bookmarkOff } from './icons/bookmark-off.svg';
and then create a manual declaration file at the project root
src/types.d.ts
declare module '*.svg' {
const src: string;
export default src;
}
It built well, but failed to generate d.ts with this error
RollupError: "default" is not exported by "src/assets/icons/ascending.svg", imported by "src/assets/icons.ts".
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too