proog / eleventy-plugin-purgecss

Eleventy plugin that runs PurgeCSS after each build
9 stars 1 forks source link

Compatibility with 11ty 3 ESM (module) mode #7

Closed notacouch closed 6 months ago

notacouch commented 8 months ago

Hello,

I am using 11ty 3 alpha5 with ESM (type: "module") mode enabled. Doesn't seem like this works with it even if the config file is in ESM: image

[11ty] Error loading the config file require() of ES Module ...\11ty\purgecss.config.js from ...\11ty\node_modules\purgecss\lib\purgecss.js not supported. [11ty] Instead change the require of purgecss.config.js in ...\11ty\node_modules\purgecss\lib\purgecss.js to a dynamic import() which is available in all CommonJS modules. (via Error)

proog commented 8 months ago

Hi!

This seems to be a limitation of PurgeCSS, as its CLI has the same issue. It attempts to require() the config file even when used in an ESM context.

As a workaround, try changing the config file extension to .cjs and specifying it explicitly:

eleventyConfig.addPlugin(purgeCssPlugin, {
  config: "./purgecss.config.cjs"
});
proog commented 6 months ago

I'm closing this, let me know if the suggestion didn't solve the issue :)

notacouch commented 6 months ago

I appreciate your prompt response back in March. I haven't had the opportunity yet to test but will definitely keep you posted once I have.