Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional dependencies in webpack

for example if I want to add require("index.less") to all files and ignore this line if the file does not exists. how do I do it (including using of loaders for example).

like image 672
Vitali Zaidman Avatar asked Aug 21 '15 10:08

Vitali Zaidman


1 Answers

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');
}
like image 116
Juho Vepsäläinen Avatar answered Sep 21 '22 16:09

Juho Vepsäläinen