11ty / eleventy-plugin-webc

Adds support for WebC *.webc files to Eleventy
https://www.11ty.dev/docs/languages/webc/
119 stars 10 forks source link

Transform Order #60

Closed korverdev closed 1 year ago

korverdev commented 1 year ago

I'm trying to minify a built HTML file, including inline CSS and JavaScript, with a custom transform.

Here's the relevant portion of my layout file where I bundle my CSS:

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

And my transform:

async function minifyHtml(content) {
    if (this.page.outputPath.endsWith(".html")) {
        return htmlMinifier.minify(content, {...});
    }
}

eleventyConfig.addTransform("minify-html", minifyHtml);

It seems my transform is running before WebC's and is receiving the following:

<style>/*__EleventyBundle:get:css:default:EleventyBundle__*/</style>

The minifier strips out the comment as expected, causing all CSS meant to be in this style tag to get dropped from the final build. I'm not sure if this is a mistake on my end or a legitimate issue with this plugin, so apologies in advance if this is intended behavior.

korverdev commented 1 year ago

It seems I was mistaken about this being an issue with this plugin. Behind the scenes, webc-plugin-bundle is used for this functionality, which does allow you to run transforms before bundling.