GoogleChromeLabs / critters

🦔 A Webpack plugin to inline your critical CSS and lazy-load the rest.

Home Page:https://npm.im/critters-webpack-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

DrJume opened this issue · comments

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

require('fs').readFile(filename, 'utf8', callback);

The only thing missing, is to add

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

to index.js.