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
When I run vite (dev preview), cssUrl.pathname returns the pathname of the css file.
When I run vite build and vite preview, cssUrl.pathname returns: text/css;base64,cCB7CiAgICBkaXNwbGF5OiBpbmxpbmUtYmxvY2s7CiAgICBjb2xvcjogcmdiKDI1NSwgMTM1LCAzMCk7Cn0KCi5yZWQgewogICAgY29sb3I6IHJlZDsKfQ==
Currently I fixed the issue with the following code:
if(this.cssUrl.pathname.startsWith("text/css;base64")){constbase64Container=this.cssUrl.pathname;constbase64=base64Container.split(",")[1];// remove the other stuffcss=atob(base64);// parse the Base64 string}else{constselfUrl=newURL("./",import.meta.url);constrelativeCssUrl=newURL(this.cssUrl.pathname,selfUrl);constcssImport=awaitimport(relativeCssUrl.pathname);css=cssImport.default;}
Is this behavior intended? How can I dynamically import CSS files without the above (hacky) code?
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
It's because CSS is considered an asset, and if it's within the build.assetsInlineLimit number, it gets base64-ed. It's technically still a URL so it should work if you need to load it. For finer-grain configuration. perhaps you want to look into #8717, but so far this is working as intended.
I don't think this should be closed. Not being able to decide what's bundled and not, is inherently a bug, though a case could be made that it's also "lacking feature". Not being able to distinguish between bundled assets and "loaded assets at build time might not be a major blocker, but it is going to cause issues like this.
Using size a static size gives little to zero control to the point that it it might have been a boolean.
Either all assets are bundled or no assets are bundled.
The size itself, is moot, since you could be hit by a thousand files and growing the bundle since the size is static.
Describe the bug
I am trying to import a CSS file dynamically. To do so, I create a new URL object like so:
When I run
vite
(dev preview), cssUrl.pathname returns the pathname of the css file.When I run
vite build
andvite preview
, cssUrl.pathname returns:text/css;base64,cCB7CiAgICBkaXNwbGF5OiBpbmxpbmUtYmxvY2s7CiAgICBjb2xvcjogcmdiKDI1NSwgMTM1LCAzMCk7Cn0KCi5yZWQgewogICAgY29sb3I6IHJlZDsKfQ==
Currently I fixed the issue with the following code:
Is this behavior intended? How can I dynamically import CSS files without the above (hacky) code?
Reproduction
https://github.com/AlexW00/component-test
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: