问题
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