Style loader module for react-web-component
npm install react-web-component-style-loader<style> tag to the web component
react-web-component-style-loader is a companion to react-web-component. When creating a web component we face the issue that we need to attach all styles to the shadow dom of the component rather than _somewhere on the page_ while still being able to use state of the art tooling (webpack) and write modular CSS across multiple files.
react-web-component. When you use this project and react-web-component, react-web-component will know where to find the CSS and write it to the shadow dom of the web component you created with it.
react-web-component-style-loader is a fork of style-loader and their README can be used for detailed usage and further information. A little more technical explanation of how this loader works: The original style loader loads the CSS from your project, creates style nodes and appends them to your website. The only real difference in this loader is that it writes the style nodes to an array in our JavaScript and react-web-component will find them and append them to the web component. It is that easy.
yarn add react-web-component-style-loader --dev
`
Basic Usage
It's recommended to combine react-web-component-style-loader with the css-loader
component.js
`js
import './file.css'
`
webpack.config.js
`js
{
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: "react-web-component-style-loader" },
{ loader: "css-loader" }
]
}
]
}
}
``
Lukas Bombach |