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

Hoist duplicated (non-default) buckets (in css and js) to default bucket #5

Closed
zachleat opened this issue Mar 2, 2023 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@zachleat
Copy link
Member

zachleat commented Mar 2, 2023

Say this island exists in two separate independent sections of a WebC page:

<is-land on:visible webc:bucket="my-bucket">
	<style webc:keep @raw="getBundle('css', 'my-bucket')"></style>

	<template data-island="once">
		<script type="module" webc:keep :src="getBundleFileUrl('js', 'my-bucket')"></script>
	</template>

	<image-compare-defined></image-compare-defined>
</is-land>

Note that this means the same bucket CSS will exist in two places on the page <style webc:keep @raw="getBundle('css', 'my-bucket')"></style>.

More simply, what should happen when we output the same non-default bundle twice?

<style webc:keep @raw="getBundle('css', 'my-bucket')"></style>
<style webc:keep @raw="getBundle('css', 'my-bucket')"></style>

Or

<style webc:keep @raw="getBundle('css', 'my-bucket')"></style>
<link rel="stylesheet" webc:keep :src="getBundleFileUrl('css', 'my-bucket')">

In those cases I’d like to hoist the CSS from the compare-defined bucket into default.

Future versions of WebC will perform this bucket hoisting more intelligently inside of WebC at a component level.

This feature is specifically for the use case when getBundle is called more than once on a single page (or getBundle is used to output the same code as getBundleFileUrl).

Notably, you exclusively use external files (getBundleFileUrl) to workaround this issue too but I think we can do better for getBundle.

@zachleat zachleat added the enhancement New feature or request label Mar 2, 2023
@zachleat zachleat changed the title Hoist duplicated (non-default) buckets to default Hoist duplicated (non-default) buckets (in css and js) to default bucket Mar 2, 2023
@zachleat
Copy link
Member Author

zachleat commented Mar 2, 2023

This behavior will be opt-in with the hoistDuplicateBundlesFor option.

Usage:

const bundlerPlugin = require("@11ty/eleventy-plugin-bundle");

module.exports = function(eleventyConfig) {
	eleventyConfig.addPlugin(bundlerPlugin, {
		hoistDuplicateBundlesFor: ["css", "js"],
	});
};

@zachleat
Copy link
Member Author

zachleat commented Mar 2, 2023

Shipping with @11ty/eleventy-plugin-bundle v1.0.2

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

1 participant