react-scripts build忽略条件css导入 [英] react-scripts build ignores conditional css imports

查看:87
本文介绍了react-scripts build忽略条件css导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的React项目有条件地要求使用CSS,并且它在本地运行.但是,当react js执行react-scripts build命令时,所有css文件都被捆绑到一个文件中,并且条件导入不再起作用.

I am trying to conditionally require css for my react project and it works locally. However, when the react-scripts build command is executed by react js all css files get bundled into one and the conditional import no longer works.

if(isSmartPhoneOrTablet()){
    require("./mobileStyle.css");
}else {
    require("./style.css");
}

"build":反应脚本构建"

推荐答案

您可以尝试

var cssfile;
if(isSmartPhoneOrTablet()){
    cssfile = "./mobileStyle.css";
}else {
    cssfile = "./style.css";
}
require(cssfile);

这篇关于react-scripts build忽略条件css导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆