Adding SVGs to the ui-lib #271
-
I have a similarly structured monorepo and would like to know what the clearest way of including svgs to the ui-lib is. Would appreciate any amount if info thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Hey @dahaca it depends if you want to publish ui-lib outside of the monorepo... If you don't have to straight away I would simply
Then ensure the consuming has the path aliases defined in its tsconfig {
"compilerOptions": {
"baseUrl": "./src",
"paths": {
// Hey Notice the '*', it will allow to impor from ui-lib subdirectories
"@your-org/ui-lib/*": [
"../../../packages/ui-libsrc/*",
],
"@your-org/ui-lib": [
"../../../packages/ui-lib/src/index",
],
},
},
}
Then to keep easy I would rely on svgr/webpack (or next-image) in the app next.config.js webpack: (config, { defaultLoaders, isServer }) => {
config.module.rules.push({
test: /\.svg$/,
issuer: /\.(js|ts)x?$/,
use: ['@svgr/webpack'],
});
return config;
}, That should allow you to simply import the svg import playIcon from '@your-org/ui-lib/icons/play.svg;
export const Header = () => (<img src={playIcon} />); // or something else You can of course add a barrel... but I'm not sure if we don't need to do something more in that case. Released an example with #278 PS: If you need to publish and use outside, it's a little more complex |
Beta Was this translation helpful? Give feedback.
-
Oh you removed the question 😄 Can you revert, it's a nice one |
Beta Was this translation helpful? Give feedback.
Hey @dahaca it depends if you want to publish ui-lib outside of the monorepo...
If you don't have to straight away I would simply
Then ensure the consuming has the path aliases defined in its tsconfig