instascan
instascan copied to clipboard
Make instascan module-friendly and greatly reduce package size
I was having issues with this library due to its dependency on babel-polyfill
, as I needed to reference babel-polyfill
on my own before this library. This was causing an error because that module insists on only being imported once. I also stumbled across #158 while searching for a solution, so I decided to take it upon myself to try and clean up the package a bit and make it more friendly in terms of compatibility with other modules and Webpack.
I changed everything to TypeScript, as this allows the usage of features such as async/await
without needing babel-polyfill
(TypeScript uses regenerator-runtime
, which is perfectly happy to be imported more than once). This also provides typings for users who consume this as a module. Most of the code is functionally identical; it's just TypeScript-ified somewhat.
The biggest change I made was to switch from the 2 MB zxing.js
library to the @zxing/library
package, which reduced the minified bundle size of this module to 373 KB (which was the post-gzipped size mentioned in #158; it now becomes around 100 KB once gzipped).
I only made one change to the API, which is that the start
function does not accept a camera. The camera can either be set using the { camera: Camera }
property on the Scanner options, or can be changed later by setting scanner.camera
and calling .start()
again. This change was due to the way the new @zxing/library
module consumes the video stream and should be fairly easy to migrate.
I made sure to update the documentation and the demo to reflect the changes. The demo was tested using a locally compiled instascan.min.js
, and should work once published as long as the rawgit
URL points to the new build artifact.
Pardon all the little commits; not super familiar with Travis
hey @briman0094,
I am using this pull request on my project. I have to say the reduced package size is pretty impressive. This should get merged with main package as well. Your package works great on webcams and androids. The only issue i'm facing is the back camera on iOS. Back camera won't open even if selected manually and automatically opens front camera. I have tested on iOS 11 and 12. Both seems to have this issue.
There are other fixes for this in newer pull requests like this one, #206 and this one, #207
Any chances you can take a look?