-
Notifications
You must be signed in to change notification settings - Fork 818
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's that also render to web #265
Comments
have a look at https://github.com/chengyin/react-primitives-svg which is the counter part of |
Fascinating, but I'm stuck. I'm only familiar with Any help on how to run these 4 examples? |
no but just use |
Oh - I gotcha. Thx |
I added
Now the peer warnings say However, they are just warnings. But |
Tried
|
Finally got it working. Thx to Lynton Ye from https://learnreact.design/. https://gist.github.com/lintonye/8e4d47dfb3089eae2462c5acced0030e It also address' this issue #220 . |
@LincMitch, I also get the |
Okey, I sort of got it working by using an relative path to the web version, import Svg from '../node_modules/react-primitives-svg/lib/core.web'; I noticed there's also a The error me and @LincMitch mentioned above comes from the fact that the main file of |
If you use webpack for bundling for the web, you will need to to add a {
...
resolve: {
// look for .web.js first
extensions: ['.web.js', '.js', '.json'],
},
...
} If you use module.exports = {
webpack: {
resolve: {
// look for .web.js first
extensions: ['.web.js', '.js', '.json'],
},
}
} |
mac os: 10.15.7 @LincMitch hey there, i have same problem: i also finding a way to convert
totally
as shown above, i typed
i
and i found this
instead
but the error is the same... so would u please give me some advices |
Hi, to render an SVG statically from a SVG string, you’ll need to use Babel to convert the string into React components. Fetching an SVG and trying to render it would’t work in React web either, you’d need to do it as a dynamic import and have it compiled by a Webpack loader. I would suggest fetching and saving the SVG files locally as a file (can be done from a Node script), then using React This can be used as part of a CLI option, or a Node.js script to fetch and save the files, just need to do a replace of |
@macintoshhelper thanks for reply, but may be i cant understand ur reply, i tried, but i failed i check this issue: Svg did not rendered as expected and config my
and installed all the loaders/packages i need, and u mentioned would u please take a while and do me a favor? that will be grateful, thanks again |
You'll need to replace
config.resolve = {
...config.resolve,
alias: {
...config.resolve.alias,
'react-sketchapp': path.resolve(__dirname, '../../'),
// PATCH <start>
'react-native-svg': path.resolve(__dirname, './Svg.js'),
// PATCH <end>
},
};
import React from 'react';
import { Svg } from 'react-sketchapp';
const {
Circle,
ClipPath,
Defs,
Ellipse,
G,
Image,
Line,
LinearGradient,
Path,
Pattern,
Polygon,
Polyline,
RadialGradient,
Rect,
Stop,
Symbol,
Text,
TextPath,
TSpan,
Use,
} = Svg;
// Disable masks in runtime
const Mask = () => <></>;
const _G = ({ mask, ...props }) => (mask ? <></> : <G {...props} />);
const _Use = ({ xlinkHref: href, ...props }) => <Use href={href} {...props} />;
const _Image = ({ xlinkHref: href, ...props }) => (
<Image href={href} {...props} />
);
export {
Mask,
Circle,
ClipPath,
Defs,
Ellipse,
_G as G,
_Image as Image,
Line,
LinearGradient,
Path,
Pattern,
Polygon,
Polyline,
RadialGradient,
Rect,
Stop,
Symbol,
Text,
TextPath,
TSpan,
_Use as Use,
};
export default Svg; From here, you'll need to debug errors you run into, as the SVGs may contain stuff that is compatible in Also, for the future, might be worth making a new issue for better visibility for others that want to import |
In the basic-svg example it shows how to import Svg and prefixing Svg. elements.
import { render, Artboard, Svg } from 'react-sketchapp';
<Svg.Path ...
How would I render this same SVG code to the web
npm run web
? Just regular svg without the prefix<path ...
I have a lot of svg icons in one file to render, so code duplication is not an option.Could we even remove the prefix, and somehow declare that any
<path
should be interpreted as<Svg.Path
?This would make current SVG to sketch example much more powerful as its not really the single point of truth, unless the same code can be rendered to a final delivery platform.
The text was updated successfully, but these errors were encountered: