Make instascan module-friendly and greatly reduce package size #176
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was having issues with this library due to its dependency on
babel-polyfill
, as I needed to referencebabel-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 needingbabel-polyfill
(TypeScript usesregenerator-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 settingscanner.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 therawgit
URL points to the new build artifact.