使用MinicsSextractPlugin时,可以将CSS作为字符串导入
我正在使用webpack。我需要将CSS文件作为字符串加载,并且可以使用CSS-Loader进行,但是我还需要使用MinicsSextrackPlugin将CSS直接注入DOM。但是,如果我使用MinicsSextractPlugin,当我尝试导入CSS时,我会收到一个空对象。
import bootstrapStyle from 'bootstrap/dist/css/bootstrap.css';
console.log(bootStrapStyle); // empty object
Webpack配置
module: {
rules: [{
test: /\.css$/,
use: [{
loader: MiniCssExtractPlugin.loader,
}, {
loader: 'css-loader',
}],
},
有没有办法实现两者?
我需要CSS作为字符串,以便将其注入Web组件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论