Optional dependencies in webpack
One option would be to set up require.context and then check if the file exists against that.
Rough idea:
var req = require.context('./', false, /^index.less$/);
if(req.keys().includes('./index.less')) {
req('./index.less');
}