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

Include bundle type to modify specific bundle output in transforms #9

Merged
merged 4 commits into from
Mar 8, 2023

Conversation

hexagoncircle
Copy link
Contributor

In the Modify the bundle output section of the README, it includes an example of how to integrate postcss in a transform function. Without a way of knowing the bundle type, this transform would cause the build to fail because it cannot process non-CSS code.

This PR will fix that issue by exposing the bundle name in a type variable available to the transform callbacks. This would allow for the postcss example to work like so:

eleventyConfig.addPlugin(pluginBundle, {
    transforms: [
      async function (content) {
        if (this.type === "css") {
          let result = await postcss([postcssNested]).process(content, {
            from: this.page.inputPath,
            to: null,
          });
          return result.css;
        }

        return content;
      },
    ],
  });

I've included a test and also updated the README to reflect this change. Let me know if there's anything else I can provide!

codeManager.js Outdated Show resolved Hide resolved
@zachleat zachleat merged commit 2569876 into 11ty:main Mar 8, 2023
@zachleat zachleat added this to the Bundle Plugin v1.0.4 milestone Mar 8, 2023
@zachleat
Copy link
Member

zachleat commented Mar 8, 2023

Shipping with v1.0.4, thank you!!

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

Successfully merging this pull request may close these issues.

2 participants