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

Chain plugin output together (formerly: How do I run a plugin after another plugin?) #1777

Open
useraccessdenied opened this issue May 15, 2021 · 2 comments
Labels

Comments

@useraccessdenied
Copy link

I have installed 2 plugins: eleventy-plugin-sass and eleventy-plugin-purgecss. I want to trim the generated CSS file but purgecss finishes before sass can compile. It purges the previously generated build and sass overwrites its output with a new CSS build.

Output from terminal

eleventy-plugin-purgecss: Using configuration ./purgecss.config.js
Wrote 2 files in 0.16 seconds (v0.12.1)
eleventy-plugin-purgecss: Writing ./public/css/index.css
[Eleventy-Plugin-Sass] Compiling Sass files...
eleventy-plugin-purgecss: Finished purging 1 file(s) in 431.0ms
[Eleventy-Plugin-Sass] Done compiling Sass files

Expected behavior
Trimmed CSS after compilation of SASS

Environment:

  • OS and Version: Ubuntu 21
  • Eleventy Version: 0.12.1
  • Node version: 15.14

Config File

const pluginSass = require("eleventy-plugin-sass");
const purgeCssPlugin = require("eleventy-plugin-purgecss");

module.exports = function (eleventyConfig) {
    eleventyConfig.addPlugin(pluginSass, {
        watch: "content/_includes/sass/**",
        outputDir: "public/css",
    });
    if (process.env.NODE_ENV === "production") {
        eleventyConfig.addPlugin(purgeCssPlugin);
    }
    return {
        dir: {
            input: "content",
            output: "public"
        }
    };
}
@pdehaan
Copy link
Contributor

pdehaan commented May 15, 2021

I don't think you're ever guaranteed that plugins will run in a specific order. For example, I just created a sample project which adds 6 fake plugins with different sleep durations (to simulate "random" execution times) and they seemed to run in parallel and finished in sometimes slightly different orders:

time npm run build

> 11ty-custom-plugins@1.0.0 build /private/tmp/11ty-custom-plugins
> eleventy

plugin::one [init] => {"ms":3000}
plugin::two [init] => {"ms":2000}
plugin::three [init] => {"ms":1000}
plugin::four [init] => {"ms":150}
plugin::five [init] => {"ms":10000}
plugin::six [init] => {"ms":2000}

Writing www/index.html from ./src/pages/home.liquid.
plugin::four [done] finished (157ms)
Wrote 1 file in 0.04 seconds (v0.12.1)

plugin::three [done] finished (1004ms)
plugin::two [done] finished (2004ms)
plugin::six [done] finished (2004ms)
plugin::one [done] finished (3008ms)
plugin::five [done] finished (10004ms)

npm run build  0.62s user 0.23s system 7% cpu 10.863 total

I imagine you'd either need to write your own plugin that compiles the Sass and runs purgecss in a specific order, or you might want to look into a build system like Gulp. In fact, I believe somebody recently just posted a link to their starter project which uses Gulp to compile Sass which might have some pointers: https://github.com/frontenso/frontenso-11ty-starter (but I'm not sure if it used purgecss, so probably needs a bit more plumbing in your case).

@zachleat
Copy link
Member

I don't think you're ever guaranteed that plugins will run in a specific order.

Whoa, really? That would be—not ideal.

addPlugin(plugin, options) {
reads as if addPlugin runs the plugin configuration functions synchronously.

Oh wait I see what y’all mean. You mean you want to chain the output of the plugins.

Marginally related comment here: #117 (comment)

@zachleat zachleat changed the title How do I run a plugin after another plugin? Chain plugin output together (formerly: How do I run a plugin after another plugin?) Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants