-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
CSS changes are not applied without ?url
(HMR)
#1062
Comments
You should use https://vite.dev/guide/assets.html#importing-asset-as-url That should effectively "include" the CSS file in the build, making Vite send the correct reload events on save, while also allowing you to load it into a stylesheet manually. |
You could also try Vite's https://vite.dev/guide/assets.html#importing-asset-as-string |
thanks! I managed to get it to work based on the advice in your first comment - but for some reason I still need the With
|
schooltape/schooltape@3cd293e |
for anyone who comes across this issue, here's a working solution: import cssString from "./some.css?url";
import "./some.css"; // needed or file change wont trigger a reload
export default defineContentScript({
matches: ["<all_urls>"],
cssInjectionMode: "manual", // needed or styles will be injected on everything that matches the match
main() {
console.log("Hello content.");
// add style with cssString
const style = document.createElement("style");
style.textContent = cssString;
document.head.appendChild(style);
},
}); I'll close this as this works now |
@aklinker1 His problem was solved with workaround, but I think it is fundamentally a bug in WXT. I tried with scaffolded projects, HMR does not work and BTW, in the vite itself, HMR works even with suffixes. |
?url
(HMR)
Alright, I debugged it and figured out the problem. So I will submit a PR. |
Describe the bug
I am manually injecting a CSS file located within
entrypoints/
entrypoints/content.ts
May be related to #386
Reproduction
pnpm install
pnpm run dev
entrypoints/some.css
- extension reloads but styles are not changedIt doesn't seem to have any effect on whether the css file is explicitly imported into the content script or not, only that the extension only reloads if there is a change and the css file has been imported by the content script. Is this intended behaviour? as the css file is located within
entrypoints/
Steps to reproduce
built files are located in
dist/
of the repo provided above (output ofpnpm dev
)System Info
System: OS: Linux 6.6 NixOS 24.11 (Vicuna) 24.11 (Vicuna) CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz Memory: 9.29 GB / 15.26 GB Container: Yes Shell: 0.98.0 - /run/current-system/sw/bin/nu Binaries: Node: 20.17.0 - /etc/profiles/per-user/willow/bin/node npm: 10.8.2 - /etc/profiles/per-user/willow/bin/npm pnpm: 9.10.0 - /etc/profiles/per-user/willow/bin/pnpm bun: 1.1.29 - /etc/profiles/per-user/willow/bin/bun Browsers: Chromium: 129.0.6668.89 npmPackages: wxt: ^0.19.11 => 0.19.11
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: