kazuhikoarase / qrcode-generator

QR Code Generator implementation in JavaScript, Java and more.
https://kazuhikoarase.github.io/qrcode-generator/js/demo/
MIT License
2.13k stars 683 forks source link

Consider exporting the library as native ES module #65

Open TomasHubelbauer opened 5 years ago

TomasHubelbauer commented 5 years ago

Hello, I'd like to request that you add support for importing this library using native ES modules, like so:

import qrcode from 'https://unpkg.com/qrcode-generator/qrcode.js';

I would benefit from this when experimenting with QR codes locally, without a build process.

I would have created a pull request, but I am not sure how to feature detect and export the library. Theoretically all you need to do is to add export default { ... }, but in browsers where ES native modules are not supported yet, this would have caused an error to be thrown. At the same time, export cannot be stated conditionally, so feature detection for native ES modules and then export doesn't seem to be possible.

I know you are not using a build process, so I am not going to suggest you create two variants, one with ES module support and one without, because this is not a pressing issue at all (can always just use script and find what I need on window.qrcode), but I am interested if you have any thoughts on how this could be achieved without introducing a build process.

fictioner commented 4 years ago

请问作者解决了吗

PhiLhoSoft commented 3 years ago

We also have this need, because we use the library in our Angular project, via the NPM release, and we get this warning:

Warning: C:\\src\app\shared\view\qrcode.service.ts depends on 'qrcode-generator'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

There is a qrcode-generator-es6 package on NPM, but it seems to be a fork, made 3 years ago, on an older version of the library (not even sure it is about this library, actually! but it kept your project blurb, even if it doesn't make sense).

Would you consider to make an ES6 module release, please? Anyway, many thanks for your great library.

GabrielDelepine commented 1 year ago

Hi

This library is hard to use in an ESM project using Typescript >= 4.7 due to the CommonJS implementation.

I could open a PR to bring ESM support but I'd like to know first if the repo's maintainer is willing to merge it or not. Please let me know