Hey all, I'm new to JS dev and looking for some help/guidence.
I have a file:
'@lib/componentMappingImports.astro'
which contains the following frontmatter:
---
import Component001 from '@components/Component001.astro';
import Component002 from '@components/Component002.astro';
export const componentMapping = {
'Component001': Component001,
'Component002': Component002,
};
---
If I manully update the imports and componentMapping object everything works as needed, but I was wondering if it is possible to 'dynamically' create both the imports and the componentMapping object using glob.
The following returns an array with he value of ['Component001', 'Component002']:
const getComponents = await Astro.glob('@components/**/*.astro');
let componentNames = getComponents.map((component: any) => component.file.split('/').pop().split('.').shift());
But this is where I'm stuck.
Any ideas if this is achievable?
Thanks for any guidence in advance.