汇总';汇总插件postsss';不要将css注入头部

汇总';汇总插件postsss';不要将css注入头部,css,web-component,rollup,Css,Web Component,Rollup,我想创建一个HTML web组件,我需要导入CSS文件,但我想将它注入到我的影子dom中。我有如下代码: import introHTML from './Intro.html'; import introCss from './Intro.css'; class IntroWebComponent extends HTMLElement{ constructor(){ super(); this.defineClassProp(); } defineClassProp(){

我想创建一个HTML web组件,我需要导入CSS文件,但我想将它注入到我的影子dom中。我有如下代码:

import introHTML from './Intro.html';
import introCss from './Intro.css';
class IntroWebComponent extends HTMLElement{

constructor(){
    super();
    this.defineClassProp();
}
defineClassProp(){
    this._shadowRoot = this.attachShadow({ mode: 'open' });
    this._html = introHTML
    this._element = document.createElement('template');
    this._element.innerHTML = this._html;
    this._element.append(`<style>${introCss}</style>`)
    this._shadowRoot.appendChild(this._element.content.cloneNode(true));
}

}
window.customElements.define('index-intro', IntroWebComponent);
import introHTML from./Intro.html';
从“./Intro.css”导入introCss;
类IntroWebComponent扩展HtmleElement{
构造函数(){
超级();
这个.defineClassProp();
}
defineClassProp(){
this._shadowRoot=this.attachShadow({mode:'open'});
这个。_html=introHTML
此._元素=document.createElement('template');
this.\u element.innerHTML=this.\u html;
此.u元素.append(`${introCss}`)
this._shadowRoot.appendChild(this._element.content.cloneNode(true));
}
}
window.customElements.define('index-intro',IntroWebComponent);

但是“rollup plugin postss”继续向我的主html头部注入css,我不知道如何停止它

只需在js模块中配置您的rollup以停止注入样式:
默认配置为:

postcss({
    inject: { insertAt: 'top' }
})
您必须将其更改为:

postcss({
  inject:false
})