react-scripts build ignores conditional css imports

耗尽温柔 提交于 2021-02-08 05:00:24

问题


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": "react-scripts build"


回答1:


You could try something like

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


来源:https://stackoverflow.com/questions/50920391/react-scripts-build-ignores-conditional-css-imports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!