feat(v2): allow import SVG images #2764
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
As a React-centric static site generator, we should definitely enable the import of SVG images into React components.
Currently when trying to import SVG there will be an expected error:
This PR also resolve #2726. Note: I don’t think we need to support the CRA format for SVG (
import {ReactComponent as SVG}
), because this can be done in custom plugin by user itself.Importing images of other extensions (jpg, png etc) is a rather difficult task due to the using of docusaurus-plugin-ideal-image plugin, although it may not be necessary right now.
docusaurus/packages/docusaurus-plugin-ideal-image/src/index.ts
Lines 28 to 42 in 463efec
In any case, SVG images is very often used in React components and we need to add support for it.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
In any React component (page or MDX document) import a SVG and try to use it, eg:
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)