I have a situation where I need to get the CSS string generated from a SASS file which has been compiled in JavaScript.
I have got a solution working with just CSS, using raw-loader
https://github.com/webpack-contrib/raw-loader
Using the following code...
import css from '!!raw-loader!../css/styles.css';
console.log(css);
However for this I need to compile the SCSS manually before I do this step which I don't really want to do.
I would prefer to do something like this... notice it is an SCSS rather than CSS file
import css from '!!raw-loader!../css/styles.scss';
console.log(css);
But this returns some JavaScript instead, I already have a SCSS loader in my webpack config which looks like this.
{
test: /\.s[ac]ss$/i,
use: [
{
loader: 'style-loader',
options: {
insert: 'head', // insert style tag inside of <head>
injectType: 'singletonStyleTag' // this is for wrap all your style in just one style tag
}
},
'css-loader',
'sass-loader'
]
},