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

imperatively adding code to bundles #25

Open
mayank99 opened this issue May 17, 2024 · 2 comments
Open

imperatively adding code to bundles #25

mayank99 opened this issue May 17, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mayank99
Copy link
Sponsor

mayank99 commented May 17, 2024

Currently, the only way to add code to a bundle is by rendering it through a template. This works fine for simple cases, but it limits the usefulness of bundles, since not everything is always an eleventy template.

It would be useful to be able to incrementally add code to the bundle without/before rendering. For example, this would come in handy if you want to populate the bundle using arbitrary JS in the ---js frontmatter or an .11ty.js file or even in the 11ty config file.

This could be exposed using an additional method under this. For example:

this.writeBundle("css", "p { color: red; }");

this.getBundle("css"); // p { color: red; }

Edits:

Related: this.getBundle currently returns a placeholder comment until after the build finishes.

  • This makes it difficult to do code transformations (e.g. using addTransform). I first noticed this when I was trying to transform some WebC output.)
  • Another thing I was trying to do is conditionally render a <style> vs a <link rel="stylesheet"> depending on the size of the code. The placeholder string makes this impossible to achieve.

(Maybe also related: I just noticed the bundleExportKey option in the readme. I wonder if that could help with the flexibility of bundles since it's JS-related. 🤔)

@zachleat
Copy link
Member

zachleat commented Jul 5, 2024

A few examples documenting bundleExportKey have popped up over at #28

@zachleat zachleat added the enhancement New feature or request label Jul 5, 2024
@mayank99
Copy link
Sponsor Author

mayank99 commented Jul 5, 2024

Ah that does clarify bundleExportKey. It's useful but not related to imperatively adding code to bundles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants