Mini-ghost / nuxt-svgo-loader

Nuxt module to load SVG files as Vue components, using SVGO for optimization.
MIT License
21 stars 3 forks source link

Usage outside of Vue Components #2

Open digitalkaoz opened 6 months ago

digitalkaoz commented 6 months ago

im having trouble using this in None-Vue-Code (still nuxt3 but on the serverside)

import Logo from "~/assets/logo.svg?raw"

export default defineEventHandler(async (event) => {
  //do something with the logo here
}

the error im getting:

 ERROR  Error: Could not load /.../assets/logo.svg?raw (imported by model/pdf.ts): ENOENT: no such file or directory,  open '/.../assets/logo.svg?raw'

so i guess the loader is not active everywhere? i guess it should?

doing the same in a vue component works flawless!

using a different loader technique (none in this case):

import Logo from "~/assets/logo.svg"
WARN  (inject plugin) rollup-plugin-inject: failed to parse /.../assets/logo.svg. Consider restricting the plugin to particular files via options.include                                                                                                                                                           10:26:40 PM

 ERROR  RollupError: Expression expected (Note that you need plugins to import files that are not JavaScript)                                                                                                                                                                                                                                           nitro 10:26:40 PM

1: <svg xmlns="http://www.w3.org/2000/svg" width="280" height="186" fill="none"><path fill="#0C4A6E" d="M20.25 175.65c.9...
   ^
digitalkaoz commented 6 months ago

i have a feeling its linked to https://github.com/jpkleemans/vite-svg-loader/pull/117 ?

Mini-ghost commented 6 months ago

I'm thinking this issue might be tied to the nitro server, which seems to struggle with importing file types like .png and .svg. If we're looking to work with raw files on the server, it might be a good idea to look into using a file system package, such as fs or fs-extra.