Less @plugin
imports of JavaScript files get run through rebaseUrls
which expects CSS contents
#19268
Open
7 tasks done
Labels
Describe the bug
Less files can contain
@plugin "plugin.js";
style imports, which reference JavaScript files. When Vite runs on a.less
file that contains a@plugin
import themakeLessWorker
function callsviteLessResolve
with theplugin.js
file (in this example), which then callsrebaseUrls
, which is expecting to have received a CSS file and runs a bunch of regex including rebasingurl(...)
s, which is breaking my JavaScript file which contains that string!I am currently investigating and I hope to be able to provide a PR…
Currently it appears that the
loadFile
function onViteLessManager
could look at theopts
to observe that theopts.mime === 'application/javascript'
and skipviteLessResolve
.Reproduction
https://github.com/karlvr/vite-less-plugin-bug
Steps to reproduce
src/main.less
file imports thesrc/plugins/test.js
plugin and then uses it in thebackground-image
attribute.src/plugins/test.js
includes the stringurl(
to demonstrate the bug, asrebaseUrls
mistakenly transforms it, thinking the file is CSSdist/assets/index-CWZCrLGA.css
demonstrates the output; theurl(...)
, which should just contain the data uri, is prefixed with the base of thesrc/plugins/test.js
file:url(plugins/data:image/png;base64...
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: