mapbox / pixelmatch

The smallest, simplest and fastest JavaScript pixel-level image comparison library
ISC License
6.1k stars 304 forks source link

pixelmatch 5 fails in browser script tags without a `module` object #110

Closed ggorlen closed 2 years ago

ggorlen commented 2 years ago

It's possible to use pixelmatch 5 in a <script> tag using the following pattern:

<script>module = {};</script>
<script src="https://cdn.jsdelivr.net/npm/pixelmatch@5.2.1/index.min.js"></script>

Older versions of pixelmatch (<= 4) don't attach to module. It adds a few bytes, but changing module.exports = pixelmatch; to module && (module.exports = pixelmatch); would make it a bit more client-friendly for those who want to use pixelmatch outside a build.

mourner commented 2 years ago

Please use the browser bundle in browser environments instead of using CommonJS with hacks: https://bundle.run/pixelmatch@5.2.0