Open poldee-lgi opened 4 years ago
I know this is an ooooold issue, but for anyone still trying to figure it out, here's how I did it.
Make sure you have the to-sass-loader
and to-string-loader
installed.
In my webpack.config:
module: {
rules: [
...
{
// look for .scss files
test: /\.scss$/,
use: [
{
loader: 'to-string-loader',
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
In your top-level React component. The dangerouslySetInnerHTML
is the important bit that you may have been missing.
import React from 'react';
import ReactDOM from 'react-dom';
import root from 'react-shadow';
import App from 'containers/App';
// To work within the shadow dom, we need to import the SASS as a string
import stylesheet from './content.styles.scss';
// attach the sidebar to the page body
const app = document.createElement('div');
app.id = 'your-root';
app.className = 'your-root';
document.body.appendChild(app);
ReactDOM.render(
<root.div>
<style dangerouslySetInnerHTML={{ __html: stylesheet }} />
<App />
</root.div>
app
);
but how does one support icons?
Hello,
I'm trying to configure my webpack config to convert my scss files to css and the insert in into my component's shadow-root context.
I'm starting to think it's not possible :-|
Example :
In my component I import my style like this. Currently, it's a style.js file
import { style, colors } from './style';
style
is defined and usable. YEAH!!colors
is defined, butcolorLogoGrey
,colorBrand
andcolorGreyActive
are all undefinedstyle.js
As you can see, I'm trying to import colors from style.scss
I've tried many different combinations with the following webpack configuration:
If I simply use
style-loader
evertything renders properly, but the<style>
tag get loaded in the head. Is it possible to set this up so the style gets bundled up inside the shadow-root?webpack starts and serves my component properly displayed and formated except for the colors and fonts.
Please help :-) Thanks