Closed floorish closed 2 years ago
Thanks for your work! I'm a little busy at the moment, but I'll look into it soon.
When this gets merged, do we still need to specify ?component
when importing an SVG with Typescript?
Yes, you still need to do that. You need to specify ?component
anyway if you set the defaultImport
to url
. If you don't change the defaultImport
setting nothing changes.
Thanks for your work
Cheers, thanks for the plugin!
Added
defaultImport
config option, to change the import type when no explicit query param is defined. Can be'url' | 'raw' | 'component'
(default is component).Testing with cypress (the following is not necessary when using vite-svg-loader in projects, this is only used for testing vite-svg-loader itself)
vite.config.js
dynamically inserts thedefaultImport
option from environment vars. Can be defined in .env:Or when calling the npm build script:
App.vue
needed to be updated, because whendefaultImport === 'url'
the following will cause an error while rendering:So that needs to be:
Therefore
vite.config.js
also dynamically resolves App.vue to either './App.vue' or './App-url.vue' depending on the SVG_DEFAULT_IMPORT environment setting.