-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
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 the makeLessWorker function calls viteLessResolve with the plugin.js file (in this example), which then calls rebaseUrls, which is expecting to have received a CSS file and runs a bunch of regex including rebasing url(...)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 on ViteLessManager could look at the opts to observe that the opts.mime === 'application/javascript' and skip viteLessResolve.
Reproduction
https://github.com/karlvr/vite-less-plugin-bug
Steps to reproduce
- The
src/main.lessfile imports thesrc/plugins/test.jsplugin and then uses it in thebackground-imageattribute. - The
src/plugins/test.jsincludes the stringurl(to demonstrate the bug, asrebaseUrlsmistakenly transforms it, thinking the file is CSS - The output
dist/assets/index-CWZCrLGA.cssdemonstrates the output; theurl(...), which should just contain the data uri, is prefixed with the base of thesrc/plugins/test.jsfile:url(plugins/data:image/png;base64...
System Info
System:
OS: macOS 15.1.1
CPU: (10) arm64 Apple M1 Max
Memory: 200.50 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
pnpm: 9.12.1 - ~/.nvm/versions/node/v20.17.0/bin/pnpm
Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 132.0.6834.83
Safari: 18.1.1
npmPackages:
@vitejs/plugin-legacy: ^6.0.0 => 6.0.0
vite: ^6.0.7 => 6.0.7Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.