jpkleemans / vite-svg-loader

Vite plugin to load SVG files as Vue components
MIT License
557 stars 59 forks source link

`?url` and `?raw` suffix support #21

Closed Thy3634 closed 2 years ago

Thy3634 commented 2 years ago

Using ?url suffix to explicit URL Imports, as well as ?raw suffix to import .svg file as string.

20 by gawlk

jpkleemans commented 2 years ago

Thanks @Thy3634 I'll look into it next week

jpkleemans commented 2 years ago

@Thy3634 Could you run the linter over your code? npm run lint

Thy3634 commented 2 years ago

Failed. So I add a submit, and the code could be linted over now.

jpkleemans commented 2 years ago

Failed. So I add a submit, and the code could be linted over now.

There are still some lint errors:

index.js:5:36: Missing space before function parentheses.
index.js:12:14: Missing space before function parentheses.
index.js:15:15: Missing space before function parentheses.
index.js:19:38: Strings must use singlequote.
index.js:20:21: Strings must use singlequote.
index.js:22:28: Strings must use singlequote.
index.js:26:20: Missing space before function parentheses.
index.js:30:38: Strings must use singlequote.
index.js:31:21: Strings must use singlequote.
index.js:39:36: Unexpected trailing comma.
index.js:40:11: Extra semicolon.
index.js:41:73: Extra semicolon.
Thy3634 commented 2 years ago

Maybe git ignored something. I add a commit via github directly. It should work.

jpkleemans commented 2 years ago

Thanks for your changes! I've added 1 comment.

jpkleemans commented 2 years ago

Thanks for your work 👍

CzBiX commented 2 years ago

This PR breaks ?url feature.

jpkleemans commented 2 years ago

@CzBiX Could you explain what exactly breaks?

CzBiX commented 2 years ago

@jpkleemans, When I write code like this:

import SvgIcon from 'foobar/demo.svg?url'

console.log(SvgIcon)

It will output the local path of file, like /home/demo/src/demo.svg, which failed to load in browser.

I hacked the code to return void in load and transform if query === 'url', then it works as my expect.