Importing multiple files containing functions in Javascript

Viewed 126

I have this tree:

/areas
    first.js
    second.js
/lib
    /first
        stuffA.js
        stuffB.js
    /second
        otherStuff01.js
        otherStuff02.js
    /utils
        commonStuff01.js
        commonStuff02.js
test.js
  • first.js and second.js contains functions that are executed in test.js;
  • all the files in /lib/first are used in first.js
  • all the files in /lib/second are used in second.js
  • files in /lib/utils are used in multiple places, e.g. print functions and similar.

Since the /areas folder will be enriched with a lot of files in the future, is there a smart way in JS to exports and require files in test.js to avoid a ton of require lines?

_

e.g. I want to avoid in test.js

const first = require('./areas/first')
const second = require('./areas/second')
...

I have to import other files in first.js and second.js too, so suggestions are very welcome!

0 Answers
Related