-
|
Dear community, I see the point of having inline SVGs because this enables you to style your SVG with stylings from outside, e.g. color variables based on the currently selected theme etc. However, since we have some big graphics displaying a lot of information, we usually want to enable the user to open specific assets in a new tab and, if desired, download them. We currently achieved this by swizzling the import MyAsset from "@site/static/docs/path/to/my/asset.svg";
<img src={MyAsset} clickable />QuestionThe problem is that due to SVGR / SVGO, the import of an SVG returns a functional React component which is hard to make openable in a new tab and downloadable. Workarounds I've tried:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Webpack allows you to force-override the active loaders for a given file extension: It's not super portable (we may move off Webpack later) but you can force this way the usage of:
One example is documented here: https://docusaurus.io/docs/markdown-features/react#importing-code-snippets Note: if your SVG is in <img src="/docs/path/to/my/asset.svg" clickable />An alternative is to use I haven't tested it but you can try this: {
test: /\.svg/,
resourceQuery: /myResourceQuery/,
type: 'asset/resource',
}import MyAsset from "@site/static/docs/path/to/my/asset.svg?myResourceQuery";Unfortunately I can't help more on Asset Modules, I was unable to finalize the adoption of this Webpack 5 feature in Docusaurus, see stale PR: #4708 |
Beta Was this translation helpful? Give feedback.
Webpack allows you to force-override the active loaders for a given file extension:
https://webpack.js.org/concepts/loaders/#inline
It's not super portable (we may move off Webpack later) but you can force this way the usage of:
One example is documented here: https://docusaurus.io/docs/markdown-features/react#importing-code-snippets
Note: if your SVG is in
/staticyou can just reference it without importing it:An alternative is to use
configureWebpack()to register an Asset Modules config: https://webpack.js.org/guides/…