New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing the default import option when no query params are given #41
Comments
Hi, thanks for the proposal. I agree having a 'default loading behavior' config option would be nice. |
Sure, I'll have a go at it |
This turned out to be a bit trickier than expected. I'm not too familiar with rollup plugins, so couple questions:
When I set the default to url instead of component via the config, it looks like dynamic imports won't work properly if it contains variables.
Is this an acceptable tradeoff? Final question: the project uses cypress to test the examples. When testing the proposed change the config of See wip here: floorish@182bb75 |
Hi, maybe something like this will work in the async load(id) {
const [path, query] = id.split('?', 2)
const importType = query || defaultImport || 'component'
if (importType === 'url') {
return // Use default svg loader
}
if (importType === 'raw') {
return `export default ${JSON.stringify(svg)}`
}
if (importType === 'component') {
// Component compilation code
}
} |
That's just a different style, right? Perhaps I'm missing something, but that doesn't address the concerns mentioned in the previous post:
I'll gladly submit a pr if you don't care about these things. |
Hi, thanks for your questions. I misinterpreted your first post.
I see, we can remove that function then. Thanks.
Yes, that is indeed a rollup specific problem. It also doesn't work for other assets:
Hmm, good question. I don't really like copying the whole folder. Can you maybe use env variables to update the config? |
No worries, thanks for your replies. I've added a pr with your suggestion: #42 |
Added in v3.2.0 |
Currently an svg without a query param is imported as a Component. Is it possible to change that to the
?url
behavior instead?Generally, I'm importing svgs as
<img/>
in Vue templates/CSS, and occasionally use the?component
query param to get a component instead. But all those<img/>
need a?url
query param, otherwise they're not loaded when using Vite build.It's a bit weird to add these
?url
params everywhere, e.g.:Particularly because the default for other assets is without query params:
And if you accidentally forget the
?url
param you'll only notice missing assets when usingvite build
. When usingvite dev
the assets are still shown correctly, so they're hard to spot when developing.Changing the default would be a breaking change, so instead a plugin config option that sets the default would be nice to have.
The text was updated successfully, but these errors were encountered: