Comments (10)
你好。没明白你说的意思,可以提供一个简单的demo吗。
from vite-plugin-crx-mv3.
我在项目中使用了 tailwindcss 这样会导致有些网站页面出现错乱,我看别的插件时使用shadow DOM来做样式隔离的,但是目前我不知道怎么注入样式,现在的样式是全局生效的,所以会导致网页布局出现错乱;
https://gitee.com/yaoyaolei/plugin-demo.git 这是一个demo
如果有解决办法麻烦请告诉我一下
目前我取消使用tailwindcss 看起来不会影响页面
比如这个网站https://www.antdv.com/components/overview 我的demo就会影响它的布局
from vite-plugin-crx-mv3.
初步看了一下,明白你意思了,我之后有空再看看怎么处理这个问题。
from vite-plugin-crx-mv3.
我也遇到了这个问题...
from vite-plugin-crx-mv3.
我在项目中使用了 tailwindcss 这样会导致有些网站页面出现错乱,我看别的插件时使用shadow DOM来做样式隔离的,但是目前我不知道怎么注入样式,现在的样式是全局生效的,所以会导致网页布局出现错乱; https://gitee.com/yaoyaolei/plugin-demo.git 这是一个demo 如果有解决办法麻烦请告诉我一下 目前我取消使用tailwindcss 看起来不会影响页面
比如这个网站https://www.antdv.com/components/overview 我的demo就会影响它的布局
在你这个例子中,可以尝试这样做。后续会想办法,在vite plugin层面做一些工作,以此简化这些写法。
// 删除src/content-scripts/App.tsx的 import "../style.css";
// src/content-scripts/content.ts 调整为以下:
import { createApp } from "vue";
import App from "./App";
import style from "../style.css?inline";
import contentClass from "./content.module.css?inline";
function loadStyle(
styleContent: string,
rootElement = document.querySelector("head")
) {
const style = document.createElement("style");
style.innerText = styleContent;
rootElement?.appendChild(style);
}
const createShadowElement = (elementId: string): Element => {
let rootElement = document.getElementById(elementId);
if (rootElement) {
const shadowMountNode = rootElement.shadowRoot?.querySelector(
`#${elementId}Children`
) as Element;
return shadowMountNode;
}
rootElement = document.createElement("div");
rootElement.setAttribute("id", elementId);
document.body.appendChild(rootElement);
const shadowRoot: any = rootElement.attachShadow({ mode: "open" });
loadStyle(style, shadowRoot);
loadStyle(contentClass, shadowRoot);
shadowRoot.defaultView = shadowRoot.ownerDocument.defaultView;
shadowRoot.createElement = function (elementName: string) {
const node = document.createElement(elementName);
Object.defineProperty(node, "ownerDocument", { value: shadowRoot });
return node;
};
const shadowMountNode = shadowRoot.createElement("div");
shadowMountNode.setAttribute("id", `${elementId}Children`);
shadowRoot.appendChild(shadowMountNode);
return shadowMountNode;
};
window.onload = () => {
const rootElement = createShadowElement("crx-app");
const app = createApp(App);
app.mount(rootElement);
};
from vite-plugin-crx-mv3.
@Jervis2049 这样写好像 vue 页面中的 style 里的样式就不生效了...
from vite-plugin-crx-mv3.
@leacoleaco 你可以试试这个plasmo
from vite-plugin-crx-mv3.
可以试试这种方案tailwindlabs/tailwindcss#9633
from vite-plugin-crx-mv3.
@panghuangdehaozi plasmo 用过了, 但是感觉它用于 react 比较友好, 用在vue 感觉好鸡肋哦....写法好麻烦
from vite-plugin-crx-mv3.
Related Issues (20)
- Unable to resolve dependency tree at example HOT 2
- TypeError: (intermediate value).mount is not a function at window.onload
- 请问有办法将popup.html 放在popup文件夹 、options.html 放在options文件夹下吗 HOT 2
- vite build started HOT 1
- How can we use `import` in `background.ts` HOT 3
- manifest->background 设置type:"module",打包后自动被去除 HOT 2
- manfest.json的 action设置为{} 后 Cannot use 'in' operator to search for 'width' in undefined HOT 2
- production: build never ends HOT 1
- window.localtion.reload是否可以添加配置控制 HOT 5
- unsafe-eval HOT 1
- newtab.html 不能用vue构建 HOT 8
- 注入js文件 HOT 11
- 插件无法运行 HOT 4
- content_scripts "world": "MAIN" 报错 HOT 7
- request support i18n HOT 1
- import 无法直接引入包 HOT 7
- svg 无法渲染 HOT 3
- 建议同步package.json 与 manifest.json 中的版本号 HOT 2
- 怎么新建配置页面,并变成更正确路径, HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-crx-mv3.