本文介绍了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导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 10:54