Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Handle SVGs as JSX. #38

Merged
merged 1 commit into from
Jan 30, 2018
Merged

Handle SVGs as JSX. #38

merged 1 commit into from
Jan 30, 2018

Conversation

pawelnvk
Copy link

This is proposal of optional way of handling importing SVGs as JSX with usage of svg-react-loader.

@papermana
Copy link

The separate variable loaders would be a good idea normally, but in this case it's going to complicate merging changes from upstream. ☹️

What do you think about doing it like so? It's maybe a little bit hacky...

[
  foo,
  bar,
  someEnvVar ? baz : null,
  qun
].filter(x => x)

@pawelnvk
Copy link
Author

I wanted to omit such hacky solutions, but when the cause is good I can't say no 😄 I will change it.

@papermana
Copy link

Alternatively, since we already only load *.inline.svg files as components, we might not use an env var to decide at all.

const useSvgLoader = allowSvgLoader || strictSvgLoader;

// This loader allows to parse SVG as JSX
if (isSvgLoaderParamDefined && useSvgLoader) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSvgLoaderParamDefined is superfluous in this case.

exclude: /node_modules/,
loader: 'svg-react-loader',
}
: {},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to do oneOf: loaders in the prod file.

README.md Outdated
@@ -65,3 +65,12 @@ Importing any stylesheet from JS (with CSS Modules enabled) will convert class n
@import '~react-select/dist/react-select';
}
```
#### 5. SVG as JSX, is it even possible?
Importing SVGs as JSX is possible, but only SVGs suffixed with `.inline` will be treated as JSX code (fe. `logo.inline.svg`):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're showing an example using logo.inline.svg just below, the crossed out part is unnecessary, I think:

Importing SVGs as JSX is possible, but only SVGs suffixed with .inline will be treated as JSX code (fe. logo.inline.svg):

@papermana papermana merged commit 54c3b8b into netguru:master Jan 30, 2018
@papermana papermana mentioned this pull request Mar 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants