shin
shin

Reputation: 343

Can't import css as string when using MiniCssExtractPlugin

I'm using webpack. I need to load a css file as a string and I'm able to do so with css-loader, but I also need to use MiniCssExtractPlugin to inject css directly into the DOM. If I use MiniCssExtractPlugin, though, when I try to import a css I receive an empty object.

import bootstrapStyle from 'bootstrap/dist/css/bootstrap.css';

console.log(bootStrapStyle); // empty object

webpack config

module: {
            rules: [{
                test: /\.css$/,
                use: [{
                    loader: MiniCssExtractPlugin.loader,
                }, {
                    loader: 'css-loader',
                }],
            },

Is there a way to achieve both?

I need the css as a string in order to inject it into a web component.

Upvotes: 5

Views: 185

Answers (0)

Related Questions