The first time I did plug-in development, First time using WXT, How to style the extension? #1002
Answered
by
aklinker1
StrawberryCake-Fish
asked this question in
Q&A
-
Hello, I am a beginner plugin developer, I have a scene right now, I mount the Svelte component to Document using an injected script. How do I style it? This is my directory structure
This is my code // content.ts
import {injectScript} from "@/utils/inject";
import {ActionEnum} from "@/common/enums/action";
import {ShowHandle} from "@/content/show-handle";
import {RuntimeMessage} from "@/common/types";
export default defineContentScript({
matches: ["*:https://*/*"],
async main() {
await injectScript("/injected.js", {
keepInDom: true,
});
},
}); // injected.ts
import {Constant} from "@/common/consts";
import App from "@/view/App.svelte";
export default defineUnlistedScript(() => {
console.log("Hello from injected.ts");
const style = document.createElement('style')
style.id = Constant.ContainerStyle
style.innerText = `html {
max-width: calc(100% - 450px) !important;
position: relative !important;
min-height:100vh !important;
}`;
document.head.appendChild(style)
const container = document.createElement("div");
container.id = Constant.ContainerRoot;
container.style.position = "fixed";
container.style.background = "#ffffff";
container.style.zIndex = "99999";
container.style.top = "0";
container.style.right = "0";
container.style.width = "450px";
container.style.height = "100%";
document.body.append(container);
new App({target: container})
}); // App.svelte
<script lang="ts">
</script>
<main style="width: 100%; height: 100%;; box-sizing: border-box; padding: 5px;">
<div class="main-container">Test</div>
</main>
<style>
:root {
width: 100%;
height: 100%;
}
.main-container {
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 5px;
}
</style> I found that the styles I wrote in Svelte didn't work, only inline styles did. What should I do to use CSS styles in my plugin development, I would appreciate it if someone could answer my questions. |
Beta Was this translation helpful? Give feedback.
Answered by
aklinker1
Sep 27, 2024
Replies: 1 comment 4 replies
-
WXT doesn't support UIs in injected scripts - put it in your content script and it will work automatically. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
StrawberryCake-Fish
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WXT doesn't support UIs in injected scripts - put it in your content script and it will work automatically.