Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack require every file in directory

This is my file structure

-main.js -SomeDir    -fileA.js    -fileB.js 

What should I do if I want to load (inside main.js) every file in someDir without specifying the file names -

something like: require(./someDir/*.js) ?

like image 714
yonatanmn Avatar asked Apr 27 '15 09:04

yonatanmn


1 Answers

Solution:

var req = require.context("../someDir", true, /^(.*\.(js$))[^.]*$/igm); req.keys().forEach(function(key){     req(key); }); // or just: req.keys().forEach(req) 

extra:

regex to match js but ignore test.js

/^(?!.*test.js)((.*\.(js\.*))[^.]*$)/igm)

like image 91
yonatanmn Avatar answered Oct 04 '22 02:10

yonatanmn