GoogleChromeLabs / critters

🦔 A Webpack plugin to inline your critical CSS and lazy-load the rest.
https://npm.im/critters-webpack-plugin
Apache License 2.0
3.42k stars 108 forks source link

Use `module.createRequire()` to fix using `require()` in ESM build #94

Closed DrJume closed 2 years ago

DrJume commented 2 years ago

The ESM build is not able to run readFile() correcly, because require('fs') is used. require() is not avaiable in ESM.

https://github.com/GoogleChromeLabs/critters/blob/5e32531caf7540842ff9af99e9449975bf0ad399/packages/critters/src/index.js#L149

The only thing missing, is to add

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

to index.js.