Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new package] Powerset barrel exports for Astro #40

Open
Fryuni opened this issue Mar 9, 2024 · 0 comments
Open

[new package] Powerset barrel exports for Astro #40

Fryuni opened this issue Mar 9, 2024 · 0 comments

Comments

@Fryuni
Copy link
Owner

Fryuni commented Mar 9, 2024

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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant