-
-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
Description
Barrel files in Astro cause the styles and scripts from all the re-exported components to be included in any page that uses any one of them.
// src/components/index.ts
export Foo from './Foo.astro';
export Bar from './Bar.astro';Then on a page:
// src/pages/index.astro
---
import {Foo} from '../components';
---
<Foo/>That index page will include the styles and client-side scripts from the Bar component.
While this is not fixed in Astro core, it could be provided as a virtual import that dynamically (and lazily) expands into the powerset of possible imports.
For the example above:
import {Foo} from '~anyComponent';would resolve to a module containing:export Foo from '/src/components/Foo.astro';
import {Bar} from '~anyComponent';would resolve to a module containing:export Bar from '/src/components/Bar.astro';
import {Foo, Bar} from '~anyComponent';would resolve to a module containing:export Bar from '/src/components/Bar.astro'; export Foo from '/src/components/Bar.astro';