features/todos.js
// Modules "must" export a constant called "name"
export const name = 'Todos';
// Your usual stuff
export default class TodosComponent {}
export const reducers = [reducer, reducer];
features/users.js
// Yet another file
export const name = 'Users';
export default class UsersComponent {}
export const reducers = [reducer, reducer];
features/app.js
import Component, { reducers } in Features from 'features/*.js';
// Transpiles to:
import _Todos_default, {
reducers as _Todos_reducers
} from 'features/todos.js';
import _Users_default, {
reducers as _Users_reducers
} from 'features/users.js';
const Features = {
Todos: {
Component: _Todos_default,
reducers: _Todos_reducers,
},
Users: {
Component: _Users_default,
reducers: _Users_reducers,
},
};
It works since the required information (modules in the "features" directory and their names) is statically available.
The problem of not being able to glob() in runtime is still there of course. You must compile any glob-using file so module paths and names are embedded in it. Another problem is that you also have to analyze the imported files to get their names before finishing analysis of the glob-using file.