Open zmsy opened 2 years ago
Has this been fixed?
@stackkrocket the issue is open and there are no PRs referencing it == not fixed.
@zmsy I found an ESBuild pluggin that adds supports for ".svg" here
@bep From, Although I would love to investigate further and take a crack at this for enhancement.
From what I understand @zmsy the solution to this is to add ".svg": api.LoaderText
here:
https://github.com/gohugoio/hugo/blob/master/resources/resource_transformers/js/options.go#L134
Note that any JavaScript ESBuild plugins you find on the interweb is not relevant for Hugo.
It is a quick fix actually. I can quickly add this.
@bep I think I may have missed some few pointer in the contributing guidelines. I wish to correct them and make subsequent adequate changes that fixes this issue.
From what I understand @zmsy the solution to this is to add
".svg": api.LoaderText
here:https://github.com/gohugoio/hugo/blob/master/resources/resource_transformers/js/options.go#L134
Note that any JavaScript ESBuild plugins you find on the interweb is not relevant for Hugo.
This seemed like the case. I haven't had the time yet to actually try building the repo with that change made and testing it, but seems like @stackkrocket is already on it 👍 Seemed like a simple update and just wanted to submit the issue first.
NOTE: For anybody reading this issue - If you're importing SVG files and you don't want Typescript to flag them with an error, you can add a .d.ts
file to your top-level assets directory (same level as your tsconfig.json
) with the file type defined:
declare module "*.svg" {
const content: string;
export default content;
}
@bep Have you had time to go through my edited commit? It seems I have passed all the checks to make a successful commit/PR.
On my site I've got a custom color theme selector, and I've got a Preact element where I'd like to inline an SVG so I can apply styles to it, and make it responsive to CSS custom properties. This is currently achieved using a custom
Figure
component:Below, using the component like so doesn't work. You'll get something akin to
JSBUILD: failed to transform "ts/index.tsx" (text/tsx): "my-icon.svg:1:0": Unexpected "<"
If you switch the file extension to
.txt
, you can import the file and render it as expected. This looks like it's because".svg"
is currently not supported in the extensions array: https://github.com/gohugoio/hugo/blob/master/resources/resource_transformers/js/options.go#L134It looks like loading SVG as text is the documented approach for using this in ESBuild, and that seems like a nice default to me.