You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sometimes you want to import with ?raw but after vite's transformation like typescript, tailwindcss, etc.
Suggested solution
if you import script from "./file.ts?raw&transform" (the syntax doesn't matter) you'll get the raw string after the typescript has been transpiled to javascript
If you want to avoid the fetch, you should be able to use ?url&inline (#12366 (comment)).
i got a data: url 🤔 i can convert it to a string using Buffer or TextDecoder but sometimes it comes as data:application/octet-stream which makes it harder to convert to a string
importdataUrlfrom"../package.json?url&inline";// Remove the prefixconstbase64Data=dataUrl.split(",")[1];// Decode the base64 dataconstbinaryData=atob(base64Data);// Convert the binary data to a stringconstresult=binaryData.toString();
but would be cool if there was a ?query to get it as a raw string
Activity
sapphi-red commentedon Apr 8, 2025
I think this is possible if #6757 is fixed.
importwith?urldoes not work with build #6757huseeiin commentedon Apr 8, 2025
isn't this unnecessary fetch() call? also how will it work in ssr?
sapphi-red commentedon Apr 9, 2025
If you want to avoid the
fetch, you should be able to use?url&inline(#12366 (comment)).huseeiin commentedon Apr 9, 2025
i got a data: url 🤔 i can convert it to a string using Buffer or TextDecoder but sometimes it comes as
data:application/octet-streamwhich makes it harder to convert to a stringhuseeiin commentedon Apr 9, 2025
nvm, its actually easy:
but would be cool if there was a ?query to get it as a raw string
huseeiin commentedon Apr 9, 2025
the typescript and jsx is not transformed as well :(
sapphi-red commentedon Apr 9, 2025
Well, that's the reason I mentioned #6757.