cozmo / jsQR

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
https://cozmo.github.io/jsQR/
Apache License 2.0
3.67k stars 606 forks source link

add esm build #135

Open shrpne opened 5 years ago

shrpne commented 5 years ago

fixes #107 and #111

This PR can be a breaking change for people who use Webpack with Babel and target ES5 browsers because it introduces module field. By default, Webpack will start to use the file specified in the module, which is ES2015. And Babel by default will not transpile it because it ignores node_modules. So bundled js will contain ES2015 code and may fail in old browsers like IE11.

So I suggest to release it under 2.0.0 and migration path will be to configure Babel properly if needed.

basz commented 4 years ago

an es module would be much appreciated... currently using https://github.com/danimoh/jsQR but that lags behind with updates.

shrpne commented 4 years ago

I have added browser field targeting UMD version. Webpack will use it by default: https://webpack.js.org/configuration/resolve/#resolvemainfields

So this PR can be merged without breaking change. But still allows using module version by importing it directly:

import jsQR from 'jsQR/dist'

Or by changing Webpack's resolve.mainFields to prefer module field instead of browser

danimoh commented 4 years ago

@basz FYI: https://github.com/danimoh/jsQR is now fully updated again and also includes several additional PR's which are still open here.