Open LironHazan opened 1 year ago
I managed to make it work with the following setting @LironHazan :
"vite-plugin-svgr": "4.1.0"
.storybook/main.ts
:
const config: StorybookConfig = {
stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'storybook-dark-mode',
],
framework: {
name: '@storybook/react-vite',
options: {
builder: {
viteConfigPath: 'libs/ui/vite.config.ts',
},
},
},
// Customize the Vite config here. <-- Added this
viteFinal: config =>
mergeConfig(config, {
plugins: [svgr({ include: '**/*.svg' })],
}),
};
Usage:
import UnixLogo from 'src/assets/svg/smile.svg';
export const SmileSVGComponent = () => (
<span className="h-6 w-6">
<Smile /* cannot make it working with className here, so hence the wrapper span :( */ />
</span>
);
I hope this help, let me know if there is a better way.
I also ran into this issue and the only way I could get it working was to downgrade to vite-plugin-svgr@3.3.0
.
It would always fail with v4 in my project, because of some combination of:
import { ReactComponent as SomeAsset } from '../path/to/asset.svg'
?react
on the end of the resolved pathesbuild-plugin-svgr
when bundling the lib (with tsup
) which does not expect ?react
on the end of the resolved paths, so even if I got v4 work working it broke the other one.I tried many different variations of options objects passed into v4 of the plugin, but nothing seemed to work for my project, so I gave up and settled for v3.
I also ran into this issue and the only way I could get it working was to downgrade to
vite-plugin-svgr@3.3.0
.It would always fail with v4 in my project, because of some combination of:
- Assets were imported using named export instead of default export, i.e.
import { ReactComponent as SomeAsset } from '../path/to/asset.svg'
- v4 of the plugin changed the include path logic to expect
?react
on the end of the resolved path- Meanwhile, I'm also using
esbuild-plugin-svgr
when bundling the lib (withtsup
) which does not expect?react
on the end of the resolved paths, so even if I got v4 work working it broke the other one.I tried many different variations of options objects passed into v4 of the plugin, but nothing seemed to work for my project, so I gave up and settled for v3.
I'm using this options for svgr and can import SVG using named export { ReactComponent as SomeAsset }. "vite-plugin-svgr": "^4.2.0", "storybook": "^7.6.17",
viteFinal: (config) => mergeConfig(config, { plugins: [svgr({ include: '**/*.svg', svgrOptions: { exportType: 'named', ref: true, svgo: false, titleProp: true } })], }),
I also ran into this issue and the only way I could get it working was to downgrade to
vite-plugin-svgr@3.3.0
. It would always fail with v4 in my project, because of some combination of:
- Assets were imported using named export instead of default export, i.e.
import { ReactComponent as SomeAsset } from '../path/to/asset.svg'
- v4 of the plugin changed the include path logic to expect
?react
on the end of the resolved path- Meanwhile, I'm also using
esbuild-plugin-svgr
when bundling the lib (withtsup
) which does not expect?react
on the end of the resolved paths, so even if I got v4 work working it broke the other one.I tried many different variations of options objects passed into v4 of the plugin, but nothing seemed to work for my project, so I gave up and settled for v3.
I'm using this options for svgr and can import SVG using named export { ReactComponent as SomeAsset }. "vite-plugin-svgr": "^4.2.0", "storybook": "^7.6.17",
viteFinal: (config) => mergeConfig(config, { plugins: [svgr({ include: '**/*.svg', svgrOptions: { exportType: 'named', ref: true, svgo: false, titleProp: true } })], }),
this worked, thanks (add import svgr from 'vite-plugin-svgr'
and it should work)
remark: I removed the options, just use svgr()
in the plugins array
Describe the bug
After upgrading (
npx storybook@latest upgrade
) from v6 to v7 I've started to get the following errors on build:pointing to an svg file (export { SvgPencil as ReactComponent };)
I'm using vite and in
.storybook/main.js
following plugins are declaredplugins: [svgrPlugin(), react()]
(vite-plugin-svgr, @vitejs/plugin-react)When running storybook
I'm getting
I'm using vite latest version (4.4.9)
Not sure what's causing those issues, and will appreciate any help!
To Reproduce
No response
System
Additional context
No response