I'm trying to export all object values as keys, in order to provide a tree-shakable import system for a plugin that I'm working on. I'm dynamically importing modules from folders and subfolders and putting them together in a giant object like this:
The structure of the object would be something like this:
components = {
"MyPluginModule1": {...},
"MyPluginModule2": {...},
...
"MyPluginModule10000": {...},
}
The number of keys can be quite a lot and I certainly cannot export them one by one manually.
I was trying to import the modules automatically from the directories (this works), but now the challenge is to export them.
const components = {};
// Now I dynamically import modules from different directories and add them in components
export {components};
However with this approach, I need to use import {components} from "...". Then I can access MyPluginModule1 as components. MyPluginModule1.
What I'd need is to be able to import MyPluginModule1 directly without needed to import the entire components array and then accessing this particular module through components.MyPluginModule1.
Goal is to import like this:
import { MyPluginModule1 } from "...";
you can probably do this:
export * from components;