-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVG import not working #2
Comments
Facing the same issue while trying this plugin |
I just took the SVGR babel plugin out of the question and created a NodeJS script to transform everything in a specified "/assets/svg" folder to a React Component. If useful to anyone, the script works like that and is run on demand as I wish (the script ignores existing components): const fs = require('fs');
const svgr = require('@svgr/core').default;
const template = require('./template');
async function transformSvgs() {
const svgFiles = fs.readdirSync('./src/assets/svgs');
for (let index = 0; index < svgFiles.length; index++) {
const svgFile = svgFiles[index];
const files = fs.readdirSync('./src/assets/svgs/components');
if (!files.includes(svgFile.replace('.svg', '.js')) && svgFile !== 'components') {
let svgCode = fs.readFileSync(`./src/assets/svgs/${svgFile}`).toString();
const camelCasedComponentName = svgFile.replace('.svg', '').replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
const capitalizedName = camelCasedComponentName.charAt(0).toUpperCase() + camelCasedComponentName.slice(1)
const jsCode = await svgr(svgCode, {
plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx', '@svgr/plugin-prettier'],
template,
},
{ componentName: capitalizedName });
fs.writeFileSync(`./src/assets/svgs/components/${svgFile.replace('.svg', '.js')}`, jsCode);
}
}
}
transformSvgs(); |
Seems like this is a cleaner solution pradel/create-react-app-esbuild#6 (comment) |
What would be the clean way to fix this ? I understood the general strategy would be like this:
As in :
(And ideally, this configuration would be done internally by the However if I simply change the webpack config as done above, compiling any
I'm new to all this, so:
|
I hope this helps someone: The
My craco.config.js configuration:
The automatic react runtime is required if you don't |
Same as pradel/create-react-app-esbuild#6, but for this plugin
Maybe CRA 4 uses SVGR babel plugin and since these plugins remove the babel-loader, it breaks things?
The text was updated successfully, but these errors were encountered: