我正在尝试有条件地要求我的反应项目使用 css,它在本地工作。 但是,当 react scripts build 命令由 react js 执行时,所有 css 文件都会捆绑成一个,条件导入不再有效。
if(isSmartPhoneOrTablet()){
require("./mobileStyle.css");
}else {
require("./style.css");
}
"build": "react-scripts build"
你可以尝试类似的东西
var cssfile;
if(isSmartPhoneOrTablet()){
cssfile = "./mobileStyle.css";
}else {
cssfile = "./style.css";
}
require(cssfile);