1

I have a lot of folders with an index.js file that consist of many lines of:

export * from './filename'

And because I want to do this for every single file in the folder I was wondering if there is a way to just have one line that just exports everything in the whole folder instead of having to do one line for each file.

Some people think the question has been answered elsewhere, but no the answer given elsewhere is to do what I am doing which is to name every file in the index. What I want is a way to say 'my index exports * from every .js file in this folder'

Odin Thorsen
  • 209
  • 1
  • 10
  • 1
    This doesn't make much sense. You have "a lot" of identically named files in the same folder? – Matt Morgan Jan 19 '18 at 12:07
  • Possible duplicate of [import modules from files in directory](https://stackoverflow.com/questions/29722270/import-modules-from-files-in-directory) – Liam Jan 19 '18 at 12:08
  • Yep, your desire is right. Makes sense to have a regex as `from` argument. But it defies ES6 standards. Please see [this](https://github.com/Microsoft/TypeScript/issues/20392). – abdul-wahab Jan 19 '18 at 12:09
  • @MattMorgan No I have a lot of folders with index files that I use to export all the functions and constants that are being exported in the files contained within the folder. I'll edit the post for clarity – Odin Thorsen Jan 19 '18 at 12:31

1 Answers1

3

Quick answer is no. Unfortunately. Reason is that you are getting a module or parts of one with the import command and every file is a module.

Sorry.

JGoodgive
  • 900
  • 7
  • 18
  • This does not answer the question, you could add a comment for that –  Jan 19 '18 at 12:11
  • Why @ashik? He asked if it could be done. I say no it cannot. Does answer his question as well as explains why. Dont down vote. – JGoodgive Jan 19 '18 at 12:25
  • 1
    ashik, this IS an answer to the question. Whether you like it or not is a complete different thing. JGoodgive, ashik has the right to downvote an answer if he does not think it is right or accurate. – Marventus Jan 19 '18 at 13:01
  • But there are ways, such as creating a script that automates populating an index file with exports, which does allow exactly that. – GeorgeWL Aug 02 '18 at 14:21