首页 > 解决方案 > Generating index.js files exporting all (thousands) components

问题描述

when looking into libraries such as material-ui, it becomes quite clear that there's some sort of script which takes care of exporting thousands of components at the same time from an index.js file.

If we look e.g. here, I can only assume that this file wasn't generated by a person (8k+ exports).

Before I reinvent the wheel, is there some standard library that one uses to create those export files? Or does rollup or some other bundler create them on the fly?

标签: reactjsnpmmaterial-ui

解决方案


This shell should do the work

for f in *.js; do
  echo "export { default as $f } from './$f'"
done

Redirect the output to a file and that's it


推荐阅读