最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Export all from folder - Stack Overflow

programmeradmin2浏览0评论

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'

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'

Share Improve this question edited Jan 19, 2018 at 12:52 Odin Thorsen asked Jan 19, 2018 at 12:04 Odin ThorsenOdin Thorsen 2893 silver badges11 bronze badges 4
  • 1 This doesn't make much sense. You have "a lot" of identically named files in the same folder? – Matt Morgan Commented Jan 19, 2018 at 12:07
  • Possible duplicate of import modules from files in directory – Liam Commented Jan 19, 2018 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. – abdul-wahab Commented Jan 19, 2018 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 Commented Jan 19, 2018 at 12:31
Add a ment  | 

1 Answer 1

Reset to default 5

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

Sorry.

发布评论

评论列表(0)

  1. 暂无评论