Closed KislyakovDS closed 1 year ago
@KislyakovDS Do you want it for async chunks? Because initial chunks just extracted and you need to insert the link tag in your HTML template, can you describe use case?
I would like similar option for mini-css-extract-plugin
to work with shadow-dom.
Example how it works with style-loader
./webpack.config.js
{
loader: "style-loader",
options: {
insert: require.resolve("./src/util/style-loader.ts"),
},
},
./src/util/style-loader.ts
const styleTags: HTMLLinkElement[] = [];
export default function (linkTag) {
styleTags.push(linkTag);
}
./src/index.ts
import { styleTags } from "./util/style-loader";
customElements.define(
"my-custom-element",
class extends HTMLElement {
async connectedCallback() {
this.attachShadow({ mode: "open" });
const myElement = document.createElement("div");
myElement.innerHTML = "Hello";
this.shadowRoot?.append(...styleTags, myElement );
}
}
);
hm, do you want to use link tag for shadow dom? I don't think it will have good perf, why not stay with style-loader?
Well, I am opened to discuss this) On the contrary, I thought to use link tag is much better, than insert many style tag in DOM. I use style-loader only for development, and in production I build css files. Why link tag will not have good perf?
Sorry for delay, missing the issue, do you still need solution/dicussion?
No, I refused from shadow-dom 😁
Feature Proposal
Add feature for insert option, which allows to setup absolute path to custom function that allows to override default behavior and insert styles at any position, like in style-loader
{ insert: require.resolve("modulePath") }
https://webpack.js.org/loaders/style-loader/#insertFeature Use Case
I am using style-loader insert option with
require.resolve("modulePath")
for my development mode, and I want same option in mini-css-extract-plugin for production buildPlease paste the results of
npx webpack-cli info
here, and mention other relevant information