一种选择是设置
require.context,然后检查该文件是否存在.
原文链接:https://www.f2er.com/javaschema/281324.html粗略的想法:
var req = require.context('./',false,/^index.less$/); if(req.keys().includes('./index.less')) { req('./index.less'); }