我已经配置了babel-css-in-js 插件,以便./app/bundle.css
在 webpack 运行babel-loader
. 我需要将此文件注入到由html-webpack-plugin
. 我试过通过css-loader
类似的方式加载它:
import './bundle.css';
const styles = cssInJs({
red: {
color: 'white',
backgroundColor: 'red',
},
});
const redClass = cx(styles.red);
function HelloWorld() {
return (<h2 className={redClass}><LoremIpsum /></h2>);
}
但我得到了错误:
client?cb1f:75 ENOTSUP: operation not supported on socket,
uv_interface_addresses
@ ./app/index.js 17:0-23
./bundle.css not found
这是我的.babelrc
:
["css-in-js", {
"vendorPrefixes":true,
"mediaMap":{
"phone": "media only screen and (max-width: 768px)",
"tablet":"media only screen and (max-width: 992px)",
"desktop":"media only screen and (max-width: 1200px)"
},
"identifier": "cssInJs",
"transformOptions":{
"presets":["env"]
},
"bundleFile": "./app/bundle.css"
}
]
html-webpack-plugin 使用html-webpack-template
它的配置,如下所示:
new HtmlWebpackPlugin({
inject: false,
mobile: true,
appMountId: 'root',
template,
}),
我可以使用其他任何机制将其注入css file
生成的模板的头部吗?
项目源码在github上